Skip to content

Instantly share code, notes, and snippets.


krakjoe/is_initialized.php Secret

Created May 26, 2021
What would you like to do?
class Foo {
private int $property;
public function __construct() {
$this->reflector = new ReflectionProperty($this, "property");
public function test() {
return is_initialized($this, "property");
public function testReflection() {
return $this->reflector->isInitialized($this);
$foo = new Foo;
$iterations = 1000000;
$start = microtime(true);
for ($count = 0; $count < $iterations; $count++)
printf("is_initialized: %.5f seconds\n", microtime(true)-$start);
$start = microtime(true);
for ($count = 0; $count < $iterations; $count++)
printf("reflection: %.5f seconds\n", microtime(true)-$start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment