php 致命错误:无法在写入上下文中使用函数返回值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5703431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:17:05  来源:igfitidea点击:

Fatal error: Can't use function return value in write context

php

提问by bm2001

the page code is all html and it wont load bec. of this error:

页面代码都是 html,它不会加载 bec。这个错误:

Fatal error: Can't use function return value in write context line 142

致命错误:无法在写入上下文第 142 行中使用函数返回值

code:

代码:

<div>
    <div class="">
        <input type="text" id="select_shelves" name="select_shelves" class="shelves_select_and_buttons" />
        <div id="shelves_menu" >
            <ul>
                <li id="li_" onclick="printValue();">option5 <= line 142 </li>
            </ul>
        </div>
    </div>
    <div class="button">
        <input type="button" onclick="dropShelves();" id="Shelves_select_button" name="Shelves_select_button" value="" class="grey_button"/>
    </div>
</div>

回答by shadyyx

If there is some PHP behind, the problem could be calling a function empty($var) in this way:

如果后面有一些 PHP,问题可能是通过这种方式调用函数 empty($var):

if(empty($var = getMyVar())) { ... }

Instead of this You should call it this way:

而不是这个你应该这样称呼它:

$var = getMyVar();
if(empty($var)) { ... }

Or better (as decezehas pointed out)

或者更好(正如deceze指出的那样)

if(!getMyVar()) { ... }

Problem causes also other similar functions (isset, is_a, is_null, etc).

问题还会导致其他类似的函数(isset、is_a、is_null 等)。

回答by Ian Wood

you are probably using something like:

你可能正在使用类似的东西:

if(empty(urFunc($foo)){
    ....
}

which won't work.

这是行不通的。

what ever it is (look for the lien number in the error to locate it) change it to:

它是什么(在错误中查找留置权号以找到它)将其更改为:

$foo = urFunc($bar);
if(empty($foo)){
    ....
}

that should fix it.

那应该解决它。