cvs: ZendEngine2 / zend_compile.c zend_object_handlers.c /tests bug39127.phpt

[email protected] ("Antony Dovgal")
Newsgroups php.zend-engine.cvs
Message-ID <cvstony20011205765624@cvsserver>
tony2001		Mon Mar 17 14:53:44 2008 UTC

  Added files:                 
    /ZendEngine2/tests	bug39127.phpt 

  Modified files:              
    /ZendEngine2	zend_compile.c zend_object_handlers.c 
  Log:
  fix #39127i (Old-style constructor fallbacks produce strange results)
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.810&r2=1.811&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.810 ZendEngine2/zend_compile.c:1.811
--- ZendEngine2/zend_compile.c:1.810	Wed Mar 12 10:40:13 2008
+++ ZendEngine2/zend_compile.c	Mon Mar 17 14:53:43 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_compile.c,v 1.810 2008/03/12 10:40:13 dmitry Exp $ */
+/* $Id: zend_compile.c,v 1.811 2008/03/17 14:53:43 tony2001 Exp $ */
 
 #include <zend_language_parser.h>
 #include "zend.h"
@@ -2417,12 +2417,19 @@
 	} else if (ce->parent->constructor) {
 		ce->constructor = ce->parent->constructor;
 		if (!zend_ascii_hash_exists(&ce->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME))) {
-			unsigned int lc_class_name_len;
-			zstr lc_class_name = zend_u_str_case_fold(ZEND_STR_TYPE, ce->name, ce->name_length, 0, &lc_class_name_len);
-
-			zend_u_hash_update(&ce->function_table, ZEND_STR_TYPE, lc_class_name, lc_class_name_len+1, ce->constructor, sizeof(zend_function), NULL);
-			function_add_ref(ce->constructor TSRMLS_CC);
-			efree(lc_class_name.v);
+			unsigned int lc_parent_class_name_len;
+			zend_function *function;
+			zstr lc_parent_class_name = zend_u_str_case_fold(ZEND_STR_TYPE, ce->parent->name, ce->parent->name_length, 0, &lc_parent_class_name_len);
+
+			if (!zend_u_hash_exists(&ce->function_table, ZEND_STR_TYPE, lc_parent_class_name, ce->parent->name_length+1) &&
+					zend_u_hash_find(&ce->parent->function_table, ZEND_STR_TYPE, lc_parent_class_name, ce->parent->name_length+1, (void **)&function)==SUCCESS) {
+				if (function->common.fn_flags & ZEND_ACC_CTOR) {
+					/* inherit parent's constructor */
+					zend_u_hash_update(&ce->function_table, ZEND_STR_TYPE, lc_parent_class_name, ce->parent->name_length+1, function, sizeof(zend_function), NULL);
+					function_add_ref(function);
+				}
+			}
+			efree(lc_parent_class_name.v);
 		}
 	}
 }
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_object_handlers.c?r1=1.196&r2=1.197&diff_format=u
Index: ZendEngine2/zend_object_handlers.c
diff -u ZendEngine2/zend_object_handlers.c:1.196 ZendEngine2/zend_object_handlers.c:1.197
--- ZendEngine2/zend_object_handlers.c:1.196	Thu Feb 21 13:55:55 2008
+++ ZendEngine2/zend_object_handlers.c	Mon Mar 17 14:53:43 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_object_handlers.c,v 1.196 2008/02/21 13:55:55 dmitry Exp $ */
+/* $Id: zend_object_handlers.c,v 1.197 2008/03/17 14:53:43 tony2001 Exp $ */
 
 #include "zend.h"
 #include "zend_globals.h"
@@ -905,9 +905,22 @@
 
 ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_uchar type, zstr function_name_strval, int function_name_strlen TSRMLS_DC) /* {{{ */
 {
-	zend_function *fbc;
+	zend_function *fbc = NULL;
+
+	if (function_name_strlen == ce->name_length && ce->constructor) {
+		zstr lc_class_name;
+		unsigned int lc_class_name_len, real_len;
+
+		lc_class_name = zend_u_str_case_fold(type, ce->name, ce->name_length, 0, &lc_class_name_len);
+		real_len = USTR_BYTES(type, lc_class_name_len);
+
+		if (!memcmp(lc_class_name.s, function_name_strval.s, real_len)) {
+			fbc = ce->constructor;
+		}
+		efree(lc_class_name.v);
+	}
 
-	if (zend_u_hash_find(&ce->function_table, type, function_name_strval, function_name_strlen + 1, (void **) &fbc)==FAILURE) {
+	if (!fbc && zend_u_hash_find(&ce->function_table, type, function_name_strval, function_name_strlen + 1, (void **) &fbc)==FAILURE) {
 		if (ce->__call &&
 		    EG(This) &&
 		    Z_OBJ_HT_P(EG(This))->get_class_entry &&

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug39127.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug39127.phpt
+++ ZendEngine2/tests/bug39127.phpt
--TEST--
Bug #39127 (Old-style constructor fallbacks produce strange results)
--FILE--
<?php

class a { function a() { var_dump("a::a() called"); } } 
class b extends a {} 

$b = new b; 
var_dump(is_callable(array($b,"a")));
var_dump(is_callable(array($b,"b")));
var_dump(is_callable(array($b,"__construct")));

echo "Done\n";
?>
--EXPECTF--	
%s(13) "a::a() called"
bool(true)
bool(false)
bool(false)
Done
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.