class Foo { public function __construct($name) { $this->name = $name; } public function hello() { echo "Hello, my name is " . $this->name . "."; } } $class = new ReflectionClass('Foo'); $obj = $class->newInstanceArgs(array('John')); $obj->hello(); //Output: Hello, my name is John.
class Bar { public function __construct() { $this->time = time(); } public function getTime() { return $this->time; } } $class = new ReflectionClass('Bar'); $obj = $class->newInstance(); echo $obj->getTime(); //Output: current timestampIn this example, a new instance of the `Bar` class is created using the `newInstance` method. This method does not take any arguments and simply calls the class constructor. The `getTime` method is then called on the object to retrieve the current timestamp. Package Library: Reflection