Last active
September 16, 2015 07:22
-
-
Save yantze/9c4442cb0dc9a2f33ab4 to your computer and use it in GitHub Desktop.
NULL is equal ''
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 | |
// http://www.phpwtf.org/ | |
$a = array(); | |
$a[''] = 'string index'; | |
$a[NULL] = 'NULL index'; | |
$a[] = 'add index'; | |
var_dump($a); | |
// NULL is equal '' | |
$b = array(); | |
$b[''] = 'string index'; | |
$b[] = 'add index'; | |
var_dump($b); | |
$a = 0; | |
$b = 'x'; | |
var_dump(FALSE == $a); | |
var_dump($a == $b); | |
var_dump($b == TRUE);\ | |
// compare integer and other type, convert integer first | |
// compare string and other type, convert string first | |
var_dump(NULL - 1); | |
// output | |
// int(-1) | |
// If you compare two numerical strings, they are compared as integers. | |
var_dump("15" == "0xF"); | |
var_dump("15" === "0xF"); | |
// bool(true) | |
// bool(false) | |
// So the restriction that the variable name can not start with a number | |
// is only enforced by the parser and even then it's fairly easy to circumvent. | |
$a = 1; | |
$$a = 'foo'; | |
print ${1}; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment