Skip to content

Instantly share code, notes, and snippets.

@stefan2904
Created June 23, 2021 16:23
Show Gist options
  • Save stefan2904/669dc8bb6395f34250ceab7cbc517731 to your computer and use it in GitHub Desktop.
Save stefan2904/669dc8bb6395f34250ceab7cbc517731 to your computer and use it in GitHub Desktop.
PHP: Check if property exists in decoded JSON (using strict types)
<?php declare(strict_types=1);
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
$j = json_decode($json);
var_dump($j);
var_dump($j->a == NULL);
//var_dump($j->a === NULL);
var_dump(property_exists($j, 'a'));
var_dump(property_exists($j, 'aaaaaaa'));
//var_dump($j->aaaaa == NULL);
//var_dump($j->aaaaa === NULL);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment