class Person { public $name; public $age; public function __construct() { $this->name = "John Doe"; $this->age = 30; } } // Instantiate a new Person object $person = new Person(); // Access the properties of the object echo $person->name; // Output: John Doe echo $person->age; // Output: 30
class Singleton { private static $instance = null; private function __construct() {} public static function getInstance() { if (self::$instance == null) { self::$instance = new Singleton(); } return self::$instance; } public function doSomething() { echo "Doing something"; } } // Instantiate a Singleton object $singleton = Singleton::getInstance(); // Call a method on the Singleton object $singleton->doSomething(); // Output: Doing somethingThe package library for self initialize in PHP would be the core PHP language as it is a built-in feature.