#44370 [Opn->Bgs]: Magic methods __set, __get, __isset, __unset are triggered if a member exists
| From: | felipe@php.net | Date: | Sat, 08 Mar 2008 15:47:20 +0000 |
| Subject: | #44370 [Opn->Bgs]: Magic methods __set, __get, __isset, __unset are triggered if a member exists | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-123070@lists.php.net to get a copy of this message | ||
ID: 44370
Updated by: felipe@php.net
Reported By: aldo at armiento dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Linux 2.6.18
PHP Version: 5.2.5
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
This is expected, you are destroing the property.
class foo {
public $test;
public function __construct() {
$this->test = 1;
}
public function __set($a, $b) {
print "set: $a\n";
}
public function __get($a) {
print "get: $a\n";
}
}
$test = new foo;
print $test->test;
unset($test->test); // destroy!
print "\n";
$test->test = 'new property';
print $test->test;
------
1
set: test
get: test
Previous Comments:
------------------------------------------------------------------------
[2008-03-08 10:36:33] aldo at armiento dot com
Description:
------------
Magic methods __set, __get, __isset, __unset are triggered also if a
member exists if accessing member from a method used in a cURL callback
function.
From the documentation instead "These methods will only be triggered
when your object or inherited object doesn't contain the member or
method you're trying to access".
Reproduce code:
---------------
<?php
class Test
{
public $member;
public function __set($sName, $mValue)
{
echo "__set() called\n";
}
public function __get($sName)
{
echo "__get() called\n";
}
public function __isset($sName)
{
echo "__isset() called\n";
}
public function __unset($sName)
{
echo "__unset() called\n";
}
public function headerCallBack($hCurl, $sHeader)
{
$this->member = 'value';
strtolower($this->member);
isset($this->member);
unset($this->member);
return strlen($sHeader);
}
public function httpGet()
{
$hCurl = curl_init();
curl_setopt($hCurl, CURLOPT_URL, 'http://www.php.net/');
curl_setopt($hCurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($hCurl, CURLOPT_HEADERFUNCTION, array($this,
'headerCallBack'));
curl_exec($hCurl);
}
}
$C = new Test();
$C->httpGet();
Expected result:
----------------
Nothing.
Actual result:
--------------
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
__set() called
__get() called
__isset() called
__unset() called
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44370&edit=1