PHP empty() strange behaviour

php

Solution

`empty()` is not a function, although it looks like a one. It's just a special syntax that works only with variables, e.g. `empty($abc)`. You simply cannot use expressions such as `empty(123)` or `empty($obj->getSth())`.

Problem

The following code (#1): ``` var_dump($myObject->getBook()->getCollection()); $testArray=Array(); var_dump($testArray); var_dump(empty($testArray)); ``` ...will output: ``` array(0) { } array(0) { } bool(true) ``` The following code (#2): ``` var_dump($myObject->getBook()->getCollection()); $testArray=Array(); var_dump($testArray); var_dump(empty($myObject->getBook()->getCollection())); ``` ...will output: Nothing. No error, not a single character. No nothing. ``` class Book{ protected $bidArray=Array(); public function getCollection(){ return $this->bidArray; } } ``` What is happening there?

Original source

Related problems