Created
October 2, 2012 15:38
-
-
Save kler/3820235 to your computer and use it in GitHub Desktop.
NULL is overwritable (scalars are not)
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 | |
// 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