From: benjiro at benjiro dot com
Operating system: Linux Debian Lenny
PHP version: 5.2.6
PHP Bug Type: Class/Object related
Bug description: __call and __set priority
Description:
------------
Unless my definition off the magic methods __call, and __set are wrong,
there seems to be a conflict between both.
When both __set & __call are defined, the __set method overrides __call,
even when the object in question is a clearly defined method.
Line1: $object->xxx( 'yyy', 'ooo' ); // At this point, __set will dominate
any call, while its clearly a method.
Line2: $object->xxx = zzz;
One expects that a method call can be recognized with (), yet, __set has a
higher priority, and thinks you are calling $object->xxx on line 1,
breaking the correct resolving to find out that its really a methode.
Reproduce code:
---------------
<?
$object = new test();
// Create john with lastname, smith, and say hello. Note: we are not
doing anything with smith in this example.
$object->john( 'smith' )->hello();
// Lets set a changed value to the changed list of object.
$object->john = xxx;
class test {
private $changed = array();
function __call ( $name, $args ) {
$this->{$name} = new child();
return $this->{$name};
}
function __get ( $name ) {
if ( isset( $this->{$name} ) )
return $this->{$name};
}
function __set ( $name, $value ) {
echo 'Lets register a possible changed value';
if ( isset( $this->{$name} ) )
$this->changed[$name] = $value;
}
}
class child {
function hello () {
echo 'Hello, im tests son, called john';
}
}
?>
Expected result:
----------------
Expected:
Hello, im tests son, called john
Lets register a possible changed value
Actual result:
--------------
Actual result is:
Lets register a possible changed value
Fatal error: Call to a member function hello() on a non-object in
/xxx/index5.php on line 5
Line 5 is in reality the method...
--
Edit bug report at http://bugs.php.net/?id=46599&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=46599&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=46599&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=46599&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=46599&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=46599&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=46599&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=46599&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=46599&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=46599&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=46599&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=46599&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=46599&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=46599&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=46599&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46599&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46599&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=46599&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=46599&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=46599&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=46599&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=46599&r=mysqlcfg