这篇文章主要介绍了PHP5.5和之前的版本empty函数的不同之处,开发时需要注意,假如你的本地开发PHP版本是PHP5.5以上,而服务器低于PHP5.5,更要注意这个问题,需要的
作为我最喜欢使用的函数之一,今天也终于发现这个函数的恶魔之处。洋洋洒洒写了以下代码,本地测试一切ok,到服务器上就SB了。
复制代码 代码如下:
if(strlen($passwd) //do something
}
大致的意思就是,密码必须大于6位切不能只由数字组成。找遍服务器日志,发现如下错误:
复制代码 代码如下:
PHP Fatal error: Can't use function return value in write context in /xxx/xxx/xx.php on line xxx
google了一下,大概是说,empty的参数不能为函数。我靠,本地明明是好的。看了下本地的PHP是5.5的,服务器是5.3的。难道这函数在2个版本之间就进化了么?找遍了PHP官方的文档没有发现任何端倪,然后google狂搜,不小心点到了PHP英文文档界面,在empty函数的介绍下面,发现了一行小字:
复制代码 代码如下:
Note:
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.
恶魔啊,,不带这么坑中文用户的。总结下empty函数的使用场景:
1.PHP 5.5之前的版本,这个函数是用来检查变量的赋值是否为0, false, 空字符串, null。任何非变量形式的参数都是导致这个函数报错。
2.PHP 5.5这个函数可以应用于任何值,而不局限于变量。可以为常量、函数返回值等等。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment