I got this error while working on a php project
Can't use method return value in write context
On this line of code.
<?php
$x = ( emtpy( get_something() ) ) ? get_something() : '';
I was searching for a good answer and found this stackoverflow post
Apparently PHP versions before 5.5 didn't support references to temporary values returned from functions.
Solution 1:
Store the returned value in a variable before testing it.
<?php
$y = get_something();
$x = ( emtpy( $y ) ) ? $y : '';
Solution 2:
Since empty is just an alias for !isset($x) || !$x
. We'll just use !
operator.
<?php
$x = ( ! get_something() ) ? get_something() : '';
I will just leave it here as a note to self.