Ask a Question related to PHP Development, Design and Development.
-
myle34 at hotmail dot com #1
#24915 [Com]: empty()/isset() misleading with __get/__set
ID: 24915
Comment by: myle34 at hotmail dot com
Reported By: tater at potatoe dot com
Status: Open
Bug Type: Zend Engine 2 problem
Operating System: OS X 10.2
PHP Version: 5CVS-2003-08-02 (dev)
New Comment:
Another solution could be to make an issetFoo($variable) function:
class foo
{
...
public function issetFoo($variable)
{
$variable = '_'.$variable;
if (isset($this->$variable)) {
return(TRUE);
}
return(FALSE);
}
}
that should work...
Previous Comments:
------------------------------------------------------------------------
[2003-09-13 20:50:56] myle34 at hotmail dot com
I have the same problem. What I would ideally like it to do is for
isset to check whether it gets a legitimate (not NULL) value from
__get() and then decide whether the variable passed to isset is set or
not. An alternative could be to have an isset_get or something to check
that it gets a good (not NULL) value returned from the __get()
function.
------------------------------------------------------------------------
[2003-08-02 07:12:58] tater at potatoe dot com
Description:
------------
Given a "property" that is really being handled by __get() and __set()
functions, you are allowed to use it with empty() and isset() without
errors or warnings, but they always report that the property is
empty/not-set.
I understand that this may not be a bug, but a "feature"
of PHP 5 - i.e., just the way it works - but if that is true,
please be kind enough to say so explicitly. It is not helpful
to mark bugs as Bogus with comments like "I suggest you read
ZEND_CHANGES :)"
If it is to be expected, it might be good to throw the
same kind of error that one would see if trying to use
empty() on a function call, if that's possible.
This is possibly related to bug #24436.
Reproduce code:
---------------
class foo
{
private $_x;
private function __get($p) { return $this->_x; }
private function __set($p,$v) { $this->_x = $v; }
}
$y = new foo;
$y->x = 12;
if (empty($y->x))
print "y->x is empty: {$y->x} \n";
else
print "y->x is not empty: {$y->x} \n";
if (isset($y->x))
print "y->x is set: {$y->x} \n";
else
print "y->x is not set: {$y->x} \n";
Expected result:
----------------
y->x is not empty: 12
y->x is set: 12
Actual result:
--------------
y->x is empty: 12
y->x is not set: 12
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=24915&edit=1[/url]
myle34 at hotmail dot com Guest
-
#25815 [Bgs]: __get & __set will not fire if the object contains reference to variable
ID: 25815 User updated by: dan at wep dot net Reported By: dan at wep dot net Status: Bogus Bug Type: ... -
#25815 [Opn->Bgs]: __get & __set will not fire if the object contains reference to variable
ID: 25815 Updated by: helly@php.net Reported By: dan at wep dot net -Status: Open +Status: Bogus... -
#24807 [Com]: Dereferencing objects and Property accesses with __get() and __set()
ID: 24807 Comment by: thomas dot hebinck at digionline dot de Reported By: Bertrand dot Willm at laposte dot net Status: ... -
[PHP-DEV] __get() and __set() in PHP 5
Yes, you are right. They only work if the variable is not defined. Andi At 08:03 PM 12/7/2003 +0100, Paul Hudson wrote: -- PHP Internals... -
__get, __set, __clone
Hi, in the past 2 days i have been looking into php5 and it's new features. I am not a psecialiste of OOP (only been OOPing for 2 month) For a...



Reply With Quote

