PHP Fatal error. Does empty () try to change the results passed to it?

There was a strange problem in PHP today, and I'm wondering if anyone can explain this. Comparing two arrays, I first tried something like this:

echo empty(array_diff( array('foo','bar') , array('bar','foo') ))

This results in the following error:

Fatal error: you cannot use the return value of a function in the context of a record

Rewriting this as ...

$dif = array_diff( array('foo','bar') , array('bar','foo') );
echo empty($dif);

... works great. An empty one should simply evaluate the value passed to it, and not write to it, so what is going wrong here? Tested in both PHP 5.2.10 and PHP 5.3.2.


I solved the problem using !count()instead empty(), but I am curious why it does not work in the first place. Is an empty()attempt to change the result of array_diff?

+3
1

manual on empty():

. empty() , . , : empty(trim($name)).

empty(), , , echo() die(), , ( ).

+10

Source: https://habr.com/ru/post/1754696/


All Articles