PHP creates objects without calling the constructor
This requirement can be achieved using PHP’s reflection feature, ReflectionClass :: newInstanceWithoutConstructor.
Example:
<?php
class a
{
public $foo=0;
public $bar=9;
public function __construct()
{
$this->foo=1;
echo "Call the constructor\n";
}
}
$ref = new ReflectionClass('a');
$inst = $ref->newInstanceWithoutConstructor();
print_r($inst);The above output:
a Object
(
[foo] => 0
[bar] => 9
)
Leave a Reply