zl程序教程

您现在的位置是:首页 >  后端

当前栏目

PHP empty()函数:Can't use method return value in write context

PHP 函数 in &# 39 value use can
2023-09-14 08:57:26 时间
<?php
if (!empty (get_gpc('userId')))
{
	$userId = get_gpc('userId');
}
else
{
	$error = "ID doesn't exist";
}

报错:

Fatal error: Can't use method return value in write context in (line number)

为什么?

empty()函数是检查一个变量是否为空,但是 get_gpc() 是个函数,所以得改下,参考代码如下:

<?php
$test = get_gpc('userId');
if (!empty($test))
{
	$userId = get_gpc('userId');
}
else
{
	$error = "ID doesn't exist";
}