On Fri, Apr 13, 2012 at 11:37 AM, Pal Konyves <paul.kony...@gmail.com> wrote: > I don't see the point of empty( function() ). > > You tipically use empty on values that holds information you want to use > later in the program flow (a string, an integer). That means you'd better > extract it to a variable because you want to avoid calling twice a function > that provides this value. You don't always need the value.
Browsing around Google it seems that one of the most common source of the function call in write context error is people trying to do if(empty(trim($xyz)). You don't necessarily need the result of trim($xyz), so it's reasonable not to save it into a temporary variable. Another example for example would be a function like this: public function isValid() { if (...) { $this->addError('xyz'); } if (...) { $this->addError('abc'); } if (...) { $this->addError('foo'); } if (...) { $this->addError('bar'); } return empty($this->getErrors()); } Furthermore you don't necessarily have to throw the return value away. For example I commonly write code like this: if (null === $result = $this->foo()) { throw new Exception(...); } $result->doSomething(); You can do something similar with empty(): if (empty($values = $this->getValues()) { return; } $this->doSomethingWith($values); I know, not everyone likes that kind of coding style, but I think it has it's uses. Nikita -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php