class Product { private $id; private $name; private $price; public function __construct($id, $name, $price) { $this->id = $id; $this->name = $name; $this->price = $price; } public function getID() { return $this->id; } } // create a new product $product = new Product(1, "iPhone X", 999.99); // get the product ID $productID = $product->getID(); echo "Product ID: " . $productID;
Product ID: 1
// assume that this code fetches a product from a database $productData = ['id' => 1, 'name' => 'MacBook Pro', 'price' => 1999.99]; // create a new product object $product = new Product($productData['id'], $productData['name'], $productData['price']); // output the product ID echo "Product ID: " . $product->getID();
Product ID: 1In these examples, we can see that the Product getID method is used to retrieve the ID of a product object that has been created or fetched from a database. The package library for this method would likely be part of an e-commerce or product management system.