tags:

views:

1604

answers:

4

I would think the following piece of code should work, but it doesn't:

if (!empty($r->getError()))

Where getError() is simply

    public function getError()
{
 return $this->error;
}

Yet I end up with this error:

can't use method return value in write context

What does this means? Isn't this just a read?

Thanks in advance!

+3  A: 

From the PHP docs:

empty() only checks variables as anything else will result in a parse error

You cannot use empty() on a function. Instead, set the return from getError() to a variable and run empty() on that.

gclaghorn
+14  A: 

It's a limitation of empty()

Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).

You'd have to change to this

$err = $r->getError();
if (!empty($err))
Peter Bailey
+1  A: 

As pointed out by others, it's a (weird) limitation of empty().

For most purproses, doing this is equal as calling empty, but this works:

if ($r->getError() != '')
Jani Hartikainen
A: 

Thanks for the help!

But i don't unterstand why it's not allowed to check wheter a return value is empty or not.

If you're looking for logic and consistency, you're using the wrong language. Not being a PHP hater here, but inconsistency and head-scratchers are a fact of life in PHP-land.
Legion