I’ve came across a strange error today in PHP. Something like:

Fatal error: Can’t use method return value in write context in {file_path}

This error is trigger by PHP’s empty language construct, because empty() can only be used on variables and not on function returns.

function f() {
    return 'Hello world';
}

// bad - will trigger an E_ERROR level exception, killing the script
if( empty( f() ) ) {
    // do something
}

// good - it works as expected
$variable = f();
if( empty( $variable ) ) {
    // do something
}

Kinda lame…