Created
March 5, 2021 18:29
-
-
Save tim-cotten/23ce74805e1b42c33f86edc5378b9d8e to your computer and use it in GitHub Desktop.
PHP Bugs: Property Problems (Proof 1)
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
<?php | |
$bird = new stdClass(); | |
$bird->name = "Mockingbird"; | |
$tail = new stdClass(); | |
$tail->color = "Brown"; | |
$tail->type = null; | |
$bird->tail = $tail; | |
echo "isset:\n"; | |
echo (int)isset($bird->tail) . "\n"; | |
echo (int)isset($bird->tail->color) . "\n"; | |
echo (int)isset($bird->wing) . "\n"; | |
echo (int)isset($bird->tail->type) . "\n"; | |
echo "\nproperty_exists:\n"; | |
echo (int)property_exists($bird, 'tail') . "\n"; | |
echo (int)property_exists($bird->tail, 'color') . "\n"; | |
echo (int)property_exists($bird, 'wing') . "\n"; | |
echo (int)property_exists($bird->tail, 'type') . "\n"; | |
// Output: | |
// isset: | |
// 1 | |
// 1 | |
// 0 | |
// 0 | |
// property_exists: | |
// 1 | |
// 1 | |
// 0 | |
// 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment