cvs: ZendEngine2 / zend_API.c /tests bug46246.phpt

[email protected] ("Dmitry Stogov")
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1223651962@cvsserver>
dmitry		Fri Oct 10 15:19:22 2008 UTC

  Added files:                 
    /ZendEngine2/tests	bug46246.phpt 

  Modified files:              
    /ZendEngine2	zend_API.c 
  Log:
  Fixed bug #46246 (difference between call_user_func(array($this, $method)) and $this->$method())
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_API.c?r1=1.489&r2=1.490&diff_format=u
Index: ZendEngine2/zend_API.c
diff -u ZendEngine2/zend_API.c:1.489 ZendEngine2/zend_API.c:1.490
--- ZendEngine2/zend_API.c:1.489	Fri Aug 22 14:51:19 2008
+++ ZendEngine2/zend_API.c	Fri Oct 10 15:19:22 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_API.c,v 1.489 2008/08/22 14:51:19 tony2001 Exp $ */
+/* $Id: zend_API.c,v 1.490 2008/10/10 15:19:22 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_execute.h"
@@ -2879,21 +2879,34 @@
 	lmname = zend_u_str_case_fold(Z_TYPE_P(callable), mname, mlen, 1, &lmlen);
 	if (zend_u_hash_find(ftable, Z_TYPE_P(callable), lmname, lmlen+1, (void**)&fcc->function_handler) == SUCCESS) {
 		retval = 1;
-	} else if (fcc->object_pp && Z_OBJ_HT_PP(fcc->object_pp)->get_method) {
-		zstr method = mname;
-		int method_len = mlen;
-
-		if (UG(unicode) && Z_TYPE_P(callable) == IS_STRING) {
-			zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &method.u, &method_len, mname.s, mlen TSRMLS_CC);
-		} else if (!UG(unicode) && Z_TYPE_P(callable) == IS_UNICODE) {
-			zend_unicode_to_string(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &method.s, &method_len, mname.u, mlen TSRMLS_CC);
-		}	
-		fcc->function_handler = Z_OBJ_HT_PP(fcc->object_pp)->get_method(fcc->object_pp, method, method_len TSRMLS_CC);
-		if (method.v != mname.v) {
-			efree(method.v);
+		if ((fcc->function_handler->op_array.fn_flags & ZEND_ACC_CHANGED) &&
+		    EG(scope) &&
+		    instanceof_function(fcc->function_handler->common.scope, EG(scope) TSRMLS_CC)) {
+			zend_function *priv_fbc;
+
+			if (zend_u_hash_find(&EG(scope)->function_table, Z_TYPE_P(callable), lmname, lmlen+1, (void **) &priv_fbc)==SUCCESS
+				&& priv_fbc->common.fn_flags & ZEND_ACC_PRIVATE
+				&& priv_fbc->common.scope == EG(scope)) {
+				fcc->function_handler = priv_fbc;
+			}
+		}
+	} else if (fcc->object_pp) {
+		if (Z_OBJ_HT_PP(fcc->object_pp)->get_method) {
+			zstr method = mname;
+			int method_len = mlen;
+
+			if (UG(unicode) && Z_TYPE_P(callable) == IS_STRING) {
+				zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &method.u, &method_len, mname.s, mlen TSRMLS_CC);
+			} else if (!UG(unicode) && Z_TYPE_P(callable) == IS_UNICODE) {
+				zend_unicode_to_string(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &method.s, &method_len, mname.u, mlen TSRMLS_CC);
+			}	
+			fcc->function_handler = Z_OBJ_HT_PP(fcc->object_pp)->get_method(fcc->object_pp, method, method_len TSRMLS_CC);
+			if (method.v != mname.v) {
+				efree(method.v);
+			}
+			retval = fcc->function_handler ? 1 : 0;
+			call_via_handler = 1;
 		}
-		retval = fcc->function_handler ? 1 : 0;
-		call_via_handler = 1;
 	} else if (fcc->calling_scope) {
 		if (fcc->calling_scope->get_static_method) {
 			fcc->function_handler = fcc->calling_scope->get_static_method(fcc->calling_scope, Z_TYPE_P(callable), mname, mlen TSRMLS_CC);

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug46246.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug46246.phpt
+++ ZendEngine2/tests/bug46246.phpt
--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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.