]> granicus.if.org Git - php/commitdiff
Fixed bug #46246 (difference between call_user_func(array($this, $method)) and $this...
authorDmitry Stogov <dmitry@php.net>
Fri, 10 Oct 2008 15:53:31 +0000 (15:53 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 10 Oct 2008 15:53:31 +0000 (15:53 +0000)
NEWS
Zend/tests/bug46246.phpt [new file with mode: 0644]
Zend/zend_execute_API.c

diff --git a/NEWS b/NEWS
index 73145a3d3efcd4a0ce5723a50ec717bcf8412041..980b34d3cce3ae398224386de6359a4631c4e89e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Oct 2008, PHP 5.2.7RC2
+- Fixed bug #46246 (difference between call_user_func(array($this, $method))
+  and $this->$method()). (Dmitry)
 - Fixed bug #44251, #41125 (PDO + quote() + prepare() can result in seg fault).
   (tsteiner at nerdclub dot net)
 
diff --git a/Zend/tests/bug46246.phpt b/Zend/tests/bug46246.phpt
new file mode 100644 (file)
index 0000000..a57222b
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+Bug #46246 (difference between call_user_func(array($this, $method)) and $this->$method())
+--FILE--
+<?php
+class A
+{
+       private function Test()
+       {
+               echo 'Hello from '.get_class($this)."\n";
+       }
+       
+       public function call($method, $args = array())
+       {
+               $this->Test();
+               $this->$method();
+               call_user_func(array($this, $method));
+       }
+}
+
+class B extends A
+{
+       protected function Test()
+       {
+               echo 'Overridden hello from '.get_class($this)."\n";
+       }
+}
+
+$a = new A;
+$b = new B;
+
+$a->call('Test');
+$b->call('Test');
+?>
+--EXPECT--
+Hello from A
+Hello from A
+Hello from A
+Hello from B
+Hello from B
+Hello from B
index dec7f67fe2916fc02c94f95279625e7bad2b6ffc..07a42b5d34825673250325ca9ccb6bab4d42002a 100644 (file)
@@ -824,7 +824,9 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
                        }
                        EX(function_state).function = 
                          Z_OBJ_HT_PP(fci->object_pp)->get_method(fci->object_pp, fname, fname_len TSRMLS_CC);
-                       if (EX(function_state).function && calling_scope != EX(function_state).function->common.scope) {
+                       if (EX(function_state).function &&
+                           (EX(function_state).function->common.fn_flags & ZEND_ACC_PRIVATE) == 0 &&
+                           calling_scope != EX(function_state).function->common.scope) {
                                char *function_name_lc = zend_str_tolower_dup(fname, fname_len);
                                if (zend_hash_find(&calling_scope->function_table, function_name_lc, fname_len+1, (void **) &EX(function_state).function)==FAILURE) {
                                        efree(function_name_lc);