The getId() method is used in PHP to retrieve the ID of an object. This method can be used in any class that implements the interface “getId()”. The getId() method returns the unique identifier of an object.
Code Examples:
Example 1:
class Car{ private $id;
function setId($id){ $this->id = $id; }
function getId(){ return $this->id; } }
$myCar = new Car(); $myCar->setId(1); echo $myCar->getId(); // Output: 1
Example 2:
class User{ private $id;
function __construct($id){ $this->id = $id; }
function getId(){ return $this->id; } }
$myUser = new User(2); echo $myUser->getId(); // Output: 2
Package/Library:
The getId() method is a built-in method in PHP and does not require a package or library. It is part of the core features of the PHP programming language.
PHP Object::getId - 30 examples found. These are the top rated real world PHP examples of Object::getId from package gxc-cms extracted from open source projects. You can rate examples to help us improve the quality of examples.