note 82940 deleted from language.oop5.overloading by felipe
| From: | felipe@php.net | Date: | Sat, 03 May 2008 17:10:42 +0000 |
| Subject: | note 82940 deleted from language.oop5.overloading by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139036@lists.php.net to get a copy of this message | ||
Note Submitter: nuttzy at spellingcow dot com
----
It should be noted that the behavior of empty() will be slightly changed even when using __isset().
There really needs to be an __empty() magic method in order to not change behavior.... but I'd
rather just not call empty() when using magic methods.
Example:
<?php
class myclass
{
private $_raw_data = array() ;
function __construct( $data)
{
$this->_raw_data = $data ;
}
function __isset( $field_name)
{
return isset($this->_raw_data[$field_name]);
}
}
$_POST['foo']='' ;
$myclass = new myclass( $_POST) ;
// correctly reports "isset"
echo (isset($myclass->foo)) ? 'isset' : 'not isset' ;
// incorrectly reports "not empty"
echo (empty($myclass->foo)) ? 'empty' : 'not empty' ;
// a way to get around the broken empty() call - correctly reports "empty"
echo ($myclass->foo) ? 'not empty' : 'empty' ;
?>