因為 PHP 5.4 以前,empty() 只能處理變數。
若直接在 empty() 放函式,會出現 Fatal error: Can't use function return value in write context 錯誤
function aa(){ return 123; } empty(aa()); // Fatal error: Can't use function return value in write context $a = aa(); empty($a); // false
官網說明:
http://php.net/manual/en/function.empty.php
Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.
沒有留言:
張貼留言