class MyClass { public static $count = 0; public function __construct() { self::$count++; } } $obj1 = new MyClass(); $obj2 = new MyClass(); $obj3 = new MyClass(); echo MyClass::$count; // Outputs: 3
class Config { public static $db = array( 'host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => 'mydb' ); } echo Config::$db['username']; // Outputs: rootIn this example, a static variable `$db` is declared and initialized to an array of configuration values. The values can be accessed using the static variable syntax `Config::$db`. Finally, the `echo` statement displays the value of the `username` key in the `$db` array, which is root. This code does not require an external package library.