note 82940 added to language.oop5.overloading
| From: | nuttzy at spellingcow dot com | Date: | Fri, 02 May 2008 20:40:19 +0000 |
| Subject: | note 82940 added to language.oop5.overloading | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139005@lists.php.net to get a copy of this message | ||
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' ;
?>
----
Server IP: 209.41.74.194
Probable Submitter: 65.47.144.166
----
Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php
Edit -- https://master.php.net/note/edit/82940
Del: integrated -- https://master.php.net/note/delete/82940/integrated
Del: useless -- https://master.php.net/note/delete/82940/useless
Del: bad code -- https://master.php.net/note/delete/82940/bad+code
Del: spam -- https://master.php.net/note/delete/82940/spam
Del: non-english -- https://master.php.net/note/delete/82940/non-english
Del: in docs -- https://master.php.net/note/delete/82940/in+docs
Del: other reasons-- https://master.php.net/note/delete/82940
Reject -- https://master.php.net/note/reject/82940
Search -- https://master.php.net/manage/user-notes.php