Skip to content

Instantly share code, notes, and snippets.

@kler
Created October 2, 2012 15:38
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 kler/3820235 to your computer and use it in GitHub Desktop.
Save kler/3820235 to your computer and use it in GitHub Desktop.
NULL is overwritable (scalars are not)
<?php
// Conclusion: NULL is in this case considered to be of no value, and PHP
// thinks that it is OK to overwrite, but integers are not treated the same
// This code will assign NULL and the ignore that NULL was assigned and create a stdClass:
$a = NULL;
$a->test = "apa"; // should warn in my oppinion
print_r($a);
// Will output:
// stdClass Object
// (
// [test] => apa
// )
// Whether this code will warn instead of overwriting the integer:
$a = 54;
$a->test = "apa";
print_r($a);
// Will output:
// PHP Warning: Attempt to assign property of non-object in Command line code on line 1
// 54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment