]> granicus.if.org Git - php/commitdiff
Fixed bug #42937 (__call() method not invoked when methods are called on parent from...
authorDmitry Stogov <dmitry@php.net>
Mon, 12 Nov 2007 09:12:06 +0000 (09:12 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 12 Nov 2007 09:12:06 +0000 (09:12 +0000)
Zend/tests/bug42937.phpt [new file with mode: 0755]
Zend/zend_object_handlers.c

diff --git a/Zend/tests/bug42937.phpt b/Zend/tests/bug42937.phpt
new file mode 100755 (executable)
index 0000000..537c567
--- /dev/null
@@ -0,0 +1,42 @@
+--TEST--
+Bug #42937 (__call() method not invoked when methods are called on parent from child class)
+--FILE--
+<?php
+class A {
+       function __call($strMethod, $arrArgs) {
+               echo "$strMethod\n";
+       }
+}
+
+class C {
+       function __call($strMethod, $arrArgs) {
+               echo "$strMethod\n";
+       }
+}
+
+class B extends A {
+       function test() {
+               self::test1();
+               parent::test2();
+               static::test3();
+               A::test4();
+               B::test5();
+               C::test6();
+       }
+}
+
+$a = new A();
+$a->test();
+
+$b = new B();
+$b->test();
+?>
+--EXPECTF--
+test
+test1
+test2
+test3
+test4
+test5
+
+Fatal error: Call to undefined method C::test6() in %sbug42937.php on line 21
index ef8ebad697dc06972706a0f13346fb268080bca8..33c2bd4f8bfc230dfc834ad51502bd16e82c0f52 100644 (file)
@@ -894,7 +894,25 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, char *f
        zend_function *fbc;
 
        if (zend_hash_find(&ce->function_table, function_name_strval, function_name_strlen + 1, (void **) &fbc)==FAILURE) {
-               if (ce->__callstatic) {
+               if (ce->__call &&
+                   EG(This) &&
+                   Z_OBJ_HT_P(EG(This))->get_class_entry &&
+                   instanceof_function(Z_OBJCE_P(EG(This)), ce TSRMLS_CC)) {
+                       zend_internal_function *call_user_call = emalloc(sizeof(zend_internal_function));
+
+                       call_user_call->type = ZEND_INTERNAL_FUNCTION;
+                       call_user_call->module = ce->module;
+                       call_user_call->handler = zend_std_call_user_call;
+                       call_user_call->arg_info = NULL;
+                       call_user_call->num_args = 0;
+                       call_user_call->scope = ce;
+                       call_user_call->fn_flags = 0;
+                       call_user_call->function_name = estrndup(function_name_strval, function_name_strlen);
+                       call_user_call->pass_rest_by_reference = 0;
+                       call_user_call->return_reference = ZEND_RETURN_VALUE;
+
+                       return (union _zend_function *)call_user_call;
+               } else if (ce->__callstatic) {
                        zend_internal_function *callstatic_user_call = emalloc(sizeof(zend_internal_function));
 
                        callstatic_user_call->type     = ZEND_INTERNAL_FUNCTION;