PHP使用empty检查函数返回结果时报Fatal error: Can't use function return value in write context的问题
2014-03-05 18:40
666 查看
PHP开发时,当你使用empty检查一个函数返回的结果时会报错:Fatal error: Can't use function return value in write context
例如:
<?php
echo empty(strlen('be-evil.org'));
到PHP手册里面查看,在empty函数描述的地方有以下文字:
Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work:empty(trim($name)).
empty() 只检测变量,检测任何非变量的东西都将导致解析错误!
因此,我们不能拿empty来直接检测函数返回的值,上面例子的解决方案如下:
<?php
$length = strlen('be-evil.org');
echo empty($length);
例如:
<?php
echo empty(strlen('be-evil.org'));
到PHP手册里面查看,在empty函数描述的地方有以下文字:
Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work:empty(trim($name)).
empty() 只检测变量,检测任何非变量的东西都将导致解析错误!
因此,我们不能拿empty来直接检测函数返回的值,上面例子的解决方案如下:
<?php
$length = strlen('be-evil.org');
echo empty($length);
相关文章推荐
- Google新的Web UI库:Polymer
- UUID(即GUID)
- NGUI官网示例8 – Scroll View(Camera)
- Longest Ordered Subsequence
- PHP中你应该知道的require()文件包含的正确用法
- APUE学习--信号(2)
- Sicily 1443. Printer Queue
- POJ 2524 Ubiquitous Religions(并查集)
- 百度UEditor开发案例(JSP)
- 改变UIViewController的push方式
- 关于ios7上无法计算UITextView的contentSize.height的解决方法
- LeetCode Question Difficulty Distribution
- grails之访问request属性
- android 获取string.xml中的value
- UIImageView
- iOS 蓝牙使用小结 bluetooth
- Arduino模拟器——不折腾就会死星人必备
- Using Notepad++ To Quickly Format XML
- add Windows build environment-mingw to qt5.2.1 on ubuntu(AMD64)
- JSP版(utf8编码)的Ueditor百度文章编辑器配置以及使用说明