Bug #63990 [Opn->Nab]: Function returns wrong when deailing with class magic methods
| From: | johannes@php.net | Date: | Tue, 15 Jan 2013 13:22:52 +0000 |
| Subject: | Bug #63990 [Opn->Nab]: Function returns wrong when deailing with class magic methods | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-176031@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63990&edit=1
ID: 63990
Updated by: johannes@php.net
Reported by: rok at andree dot si
Summary: Function returns wrong when deailing with class
magic methods
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5.3Git-2013-01-15 (snap)
Block user comment: N
Private report: N
New Comment:
isset() and empty() call the __isset() magic method, not __get.
Previous Comments:
------------------------------------------------------------------------
[2013-01-15 12:27:20] rok at andree dot si
Description:
------------
---
From manual page: http://www.php.net/function.empty#refsect1-function.empty-description
---
When testing a property of a class with empty(),
when this property is served by __get magic method
when this property is NOT EMPTY
empty() will return TRUE
and display no error or warning
This has been tested on:
PHP 5.3.6-13ubuntu3.7 with Suhosin-Patch (cli) (built: May 4 2012 00:50:06)
and
http://writecodeonline.com/php/
Test script:
---------------
$v = "11.10.2012 13:26:21";
$test = new a();
$test->b = $v;
echo $test->b;
$r = empty($test->b);
var_dump($r);
class a {
protected $b;
/*
* Magic
*/
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}
}
/*
* Magic
*/
public function __set($property, $value) {
if (property_exists($this, $property)) {
$this->$property = $value;
}
}
}
Expected result:
----------------
11.10.2012 13:26:21bool(false)
OR
Error along the lines of:
Fatal error: Can't use function return value in write context on line N
Actual result:
--------------
11.10.2012 13:26:21bool(true)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63990&edit=1