#40797 [Opn->Csd]: overloading with __isset() also affects empty()
| From: | vrana@php.net | Date: | Fri, 23 Mar 2007 14:24:54 +0000 |
| Subject: | #40797 [Opn->Csd]: overloading with __isset() also affects empty() | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969375834@lists.php.net to get a copy of this message | ||
ID: 40797
Updated by: vrana@php.net
Reported By: stephan_schmidt at usa dot com
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Windows 200X
PHP Version: 5.2.1
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
"Method __isset is called also with empy()."
Previous Comments:
------------------------------------------------------------------------
[2007-03-15 15:08:29] bjori@php.net
Re-opening & update summary
------------------------------------------------------------------------
[2007-03-15 14:32:24] stephan_schmidt at usa dot com
Thanks. The fact that overloading with __isset() also affects empty()
should be documented somewhere, as the page on overloading
(http://us3.php.net/manual/en/language.oop5.overloading.php) contains
only examples for isset().
------------------------------------------------------------------------
[2007-03-14 11:24:32] dmitry@php.net
To make isset() and empty() work with overloaded properties you must
implement __isset() magic method, otherwise isset() and empty() check
for regular properties.
<?php
class A {
public $myArray = array('nonEmptyVar' => 5, 'emptyVar' => '');
function __get($var) {
return $this->myArray[$var];
}
function __isset($var) {
return isset($this->myArray[$var]);
}
}
$a = new A();
echo empty($a->nonEmptyVar) ? 'empty' : 'not empty';
echo '<br>';
echo empty($a->emptyVar) ? 'empty' : 'not empty';
?>
------------------------------------------------------------------------
[2007-03-14 01:36:16] tony2001@php.net
Dmitry, please take a look at zend_std_has_property().
------------------------------------------------------------------------
[2007-03-14 00:57:08] stephan_schmidt at usa dot com
The "Actual Results" were from the results of the above script run on a
clean install of PHP 5.2.1 (Win 2000 SP4). No zend extensions are
present or in use.
The code above did not run as expected on any of the Win 200X servers
it was tested on. Line 6 of the output read "int(5) empty" in every test
case.
I suspect it may have to do with the fact that empty() does not accept
a function call as a parameter (i.e. empty(trim($myVar))) since
overloading calls __get. However, one would expect it to also result in
a fatal error if that were the case.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/40797
--
Edit this bug report at http://bugs.php.net/?id=40797&edit=1