forked from php/php-src
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add property_initialized
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--TEST-- | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
private int $foo; | ||
|
||
public function propertyInitialized($name): bool | ||
{ | ||
if (property_exists($this, $name)) { | ||
try { | ||
return $this->$name === null || $this->$name !== null; | ||
} Catch(Error $e) { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
$s = microtime(true); | ||
$foo = new Foo(); | ||
for ($i = 0; $i < 10000; $i++) { | ||
$foo->propertyInitialized('foo'); | ||
} | ||
|
||
echo number_format(microtime(true) - $s, 6) . "\n"; | ||
|
||
$s = microtime(true); | ||
$foo = new Foo(); | ||
for ($i = 0; $i < 10000; $i++) { | ||
property_initialized($foo, 'foo'); | ||
} | ||
|
||
echo number_format(microtime(true) - $s, 6) . "\n"; | ||
|
||
?> | ||
--EXPECTF-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters