一、如果有一个字符串变量等于'error',它跟0 == 运算时,会返回true,但是它并不是一个预置常量
$test = 'error'; var_dump($test == 0);//true
二、调用unset会触发对象的__destruct()方法,但是只有在对象在zval的refcount值为0时(即已经没有变量(symbol)引用这个zval时),才会触发
class test1 { public function __destruct() { print "Destroying test1. "; } } $a = new test1(); $b = $a; unset($a);//当只unset($a)时,不会触发__destruct() unset($b);//这里才会触发__destruct() echo "now exit. ";
三、__destruct()方法不会销毁类的静态属性
class test1 { public static $id = 'test1'; public function foo(){ static::$id .= '_extends'; } public function __destruct() { print "Destroying test1. "; } } $a = new test1(); $b = $a; $b->foo(); unset($a);//当只unset($a)时,不会触发__destruct() unset($b);//这里才会触发__destruct() echo test1::$id." ";//test1::$id不会被销毁 echo "now exit. ";
四、对象被销毁的同时,它的动态属性也会被自动销毁,并不需要手动去销毁动态属性
class test1 { public function __destruct() { print "Destroying test1. "; } } class test2 { public $test1 = NULL; public function __destruct() { print "Destroying test2. "; } } $a = new test1(); $b = new test2(); $b->test1 = $a; unset($a);//当只unset($a)时,不会触发__destruct() unset($b);//当b被销毁,意味着b的所有属性值(symbol)也会被销毁,所以b销毁后会触发a被销毁 echo "now exit. ";
五、单引号所谓的“转义序列将不会被替换”并不包含""和"'",""遇到本身或者单引号时还是会被替换,所以下面的示例中"\"在脚本被解释后等同于"",
php函数json_encode接收到的键'b'的值,实际上是'CM001'.
<?php $arr = array( 'a' => 'CM001', 'b' => 'CM00\1', ); echo json_encode($arr);
$.ajax({ "url": "./temp_185.php", "dataType": "text", "success": function(data){ console.log(data); //output: {"a":"CM00\1","b":"CM00\1"} } });
六、在命名空间中,不能包含有public|protected|private字符,会导致php解析报语法错误
Parse error: syntax error, unexpected 'protected' (T_PROTECTED), expecting identifier (T_STRING) in /xxx/xxx/xxx