ID: 47100
User updated by: dreadlabs at gmail dot com
Reported By: dreadlabs at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Ubuntu
PHP Version: 5.2.8
New Comment:
Henrique,
Thanks for that, i completely forgot about the php4 backwards
compatibility. I havent used php4 in so long that it totally slipped my
mind.
Bug set as bogus.
Previous Comments:
------------------------------------------------------------------------
[2009-01-15 03:02:44] typoon at gmail dot com
Think about it for a minute. If you class is called '__call' and you
declare a function '__call', that one would be the constructor right?
The error you experience is that you are calling the constructor without
the parameters it expects.
Check this code:
<?php
class __call {
public function __call($method, $args){
echo $method."\n";
}
public function test() {
echo "i am test\n";
}
}
$obj = new __call('my method','arguments');
$obj->test();
?>
So, either PHP should not allow a class to have the same name as magic
methods, or you need to play with the idea that the constructor comes
first.
Other 'workaround' for this would be:
<?php
class __call {
public function __construct(){}
public function __call($method, $args){
echo $method."\n";
}
public function test() {
echo "i am test\n";
}
}
$obj = new __call('my method','arguments');
$obj->test();
$obj2 = new __call;
?>
Now you have a __construct() function, so __call can be used normally.
Regards,
Henrique
------------------------------------------------------------------------
[2009-01-14 17:54:44] dreadlabs at gmail dot com
Personally, i dont see why you would raise a fatal error when using
magic methods for class names, you're not conflicting with anything, it
should allow you to use it as normal.
------------------------------------------------------------------------
[2009-01-14 17:42:53] crrodriguez at opensuse dot org
Interesting.. in reality it IMHO should abort with a fatal error when
classes are named __construct, __destruct, __call, __callStatic, __get,
__set, __isset, __unset, __sleep, __wakeup, __toString, __set_state and
__clone.
------------------------------------------------------------------------
[2009-01-14 15:11:04] dreadlabs at gmail dot com
Description:
------------
I created a class named __call, within that class i created the magic
method __call. I then instantiated the __call class and tried to call a
non-existent method. I then got a missing argument error from PHP,
instead of it using the __call method.
Reproduce code:
---------------
<?php
class __call {
public function __call($method, $args){
echo $method."\n";
}
}
$obj = new __call;
$obj->test();
?>
Expected result:
----------------
test
Actual result:
--------------
Warning: Missing argument 1 for __call::__call(), called in
/home/tam/test.php on line 15 and defined in /home/tam/test.php on line
5
Warning: Missing argument 2 for __call::__call(), called in
/home/tam/test.php on line 15 and defined in /home/tam/test.php on line
5
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47100&edit=1