Skip to content

Instantly share code, notes, and snippets.

@tim-cotten
Created March 5, 2021 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tim-cotten/23ce74805e1b42c33f86edc5378b9d8e to your computer and use it in GitHub Desktop.
Save tim-cotten/23ce74805e1b42c33f86edc5378b9d8e to your computer and use it in GitHub Desktop.
PHP Bugs: Property Problems (Proof 1)
<?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