]> granicus.if.org Git - php/commitdiff
MFH: fix #39127 (Old-style constructor fallbacks produce strange results)
authorAntony Dovgal <tony2001@php.net>
Mon, 17 Mar 2008 14:54:42 +0000 (14:54 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 17 Mar 2008 14:54:42 +0000 (14:54 +0000)
Zend/tests/bug39127.phpt [new file with mode: 0644]
Zend/zend_compile.c
Zend/zend_object_handlers.c

diff --git a/Zend/tests/bug39127.phpt b/Zend/tests/bug39127.phpt
new file mode 100644 (file)
index 0000000..a013da1
--- /dev/null
@@ -0,0 +1,21 @@
+--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--    
+string(13) "a::a() called"
+bool(true)
+bool(false)
+bool(false)
+Done
index 2e2c0fae930ca76fc82d0f7671aa5cb0ee8109a4..f6af8c84aa0141dc9f2fc67f73a6f31ad93f67cb 100644 (file)
@@ -2197,10 +2197,11 @@ static void do_inherit_parent_constructor(zend_class_entry *ce)
                lc_class_name = zend_str_tolower_dup(ce->name, ce->name_length);
                if (!zend_hash_exists(&ce->function_table, lc_class_name, ce->name_length+1)) {
                        lc_parent_class_name = zend_str_tolower_dup(ce->parent->name, ce->parent->name_length);
-                       if (zend_hash_find(&ce->parent->function_table, lc_parent_class_name, ce->parent->name_length+1, (void **)&function)==SUCCESS) {
+                       if (!zend_hash_exists(&ce->function_table, lc_parent_class_name, ce->parent->name_length+1) && 
+                                       zend_hash_find(&ce->parent->function_table, 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_hash_update(&ce->function_table, lc_class_name, ce->name_length+1, function, sizeof(zend_function), NULL);
+                                       zend_hash_update(&ce->function_table, lc_parent_class_name, ce->parent->name_length+1, function, sizeof(zend_function), NULL);
                                        function_add_ref(function);
                                }
                        }
index 449c32408be6f6aa37a73377e42dda303298d080..5ec5826d613ceeb213bb0015fbc12ad0ee933f4a 100644 (file)
@@ -892,9 +892,17 @@ ZEND_API void zend_std_callstatic_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{
 
 ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, char *function_name_strval, int function_name_strlen TSRMLS_DC) /* {{{ */
 {
-       zend_function *fbc;
+       zend_function *fbc = NULL;
+       char *lc_class_name;
 
-       if (zend_hash_find(&ce->function_table, function_name_strval, function_name_strlen + 1, (void **) &fbc)==FAILURE) {
+       if (function_name_strlen == ce->name_length && ce->constructor) {
+               lc_class_name = zend_str_tolower_dup(ce->name, ce->name_length);
+               if (!memcmp(lc_class_name, function_name_strval, function_name_strlen)) {
+                       fbc = ce->constructor;
+               }
+               efree(lc_class_name);
+       }
+       if (!fbc && zend_hash_find(&ce->function_table, function_name_strval, function_name_strlen+1, (void **) &fbc)==FAILURE) {
                if (ce->__call &&
                    EG(This) &&
                    Z_OBJ_HT_P(EG(This))->get_class_entry &&