From 8e3aebd5504cac42d296b16b8ed1b210de67427a Mon Sep 17 00:00:00 2001 From: Scott MacVicar Date: Thu, 18 Jun 2009 13:46:16 +0000 Subject: [PATCH] Fix bug #48215 - Calling a method with the same name as the parent class calls the constructor instead. --- Zend/tests/bug48215.phpt | 38 +++++++++++++++++++++++++++++++++++++ Zend/zend_object_handlers.c | 4 +++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/bug48215.phpt diff --git a/Zend/tests/bug48215.phpt b/Zend/tests/bug48215.phpt new file mode 100644 index 0000000000..99c4dd289b --- /dev/null +++ b/Zend/tests/bug48215.phpt @@ -0,0 +1,38 @@ +--TEST-- +Bug #48215 - parent::method() calls __construct +--FILE-- +A(); +?> +===DONE=== +--EXPECTF-- + +Strict Standards: Redefining already defined constructor for class A in %s on line %d +B::__construct +A::__construct +B::A +A::A +===DONE=== diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 0e0b976032..6848977ae3 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -28,6 +28,7 @@ #include "zend_object_handlers.h" #include "zend_interfaces.h" #include "zend_closures.h" +#include "zend_compile.h" #define DEBUG_OBJECT_HANDLERS 0 @@ -941,7 +942,8 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, char *f 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)) { + /* Only change the method to the constructor if a __construct() method doesn't exist */ + if (!memcmp(lc_class_name, function_name_strval, function_name_strlen) && memcmp(ce->constructor->common.function_name, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME))) { fbc = ce->constructor; } efree(lc_class_name); -- 2.40.0