class Person { static $count; static function init() { self::$count = 0; } function __construct() { self::$count += 1; } } Person::init(); $person1 = new Person(); $person2 = new Person(); echo Person::$count; // Output: 2
namespace MyPackage; class Car { static $models = []; static function addModel($model) { array_push(self::$models, $model); } } Car::addModel("Toyota"); Car::addModel("Honda"); echo implode(", ", Car::$models); // Output: "Toyota, Honda"In this example, we define a `Car` class inside a namespace called `MyPackage`. The `addModel()` function is used to add car models to the static `$models` variable, which is an array. Finally, we display the list of car models using `implode()` function. The package library used in these examples is the PHP core library, as static initialization is a built-in feature of PHP.