contao/test — Issue #2897: Add __isset() magic method to classes for proper support of PHP's empty()
Author: importer
Created: 2011-11-29 10:31:17+00:00
State: open
Labels: Feature, framework

Hi,

due to having some trouble with debugging my extension code here I encountered some trouble with using empty() (again). Since Contao classes such as Template are using magic getter method to transparently provide access on otherwise protected properties, it's intentional to pass those retrieved properties into methods such as empty() ... but the latter is slightly misbehaving from an external point of view in current releases of PHP and thus resulting in confusing results. Before invoking __get() for reading the value, it's using magic method __isset() to see if selected property is set at all. If that method is missing, it's considering property missing as well and thus indicating empty property even though it's an array with elements available by __get() ...

Could you please add that magic method to those base classes?

Try this code for testing and remove the __isset() to illustrate the problem:

```
array( 1 ) );

public function __get( $name ) { return $this->data[$name]; }
public function __isset( $name ) { return isset( $this->data[$name] ); }
}

$a = new A;
var_dump( count( $a->test ) );
var_dump( empty( $a->test ) );
```

Best Regards!

--- _Originally created by soletan on February 28th, 2011, at 01:26pm (ID 2897)_