mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Fix bug #48215 - Calling a method with the same name as the parent class calls the constructor instead.
This commit is contained in:
parent
b2d3c2bf18
commit
8e3aebd550
38
Zend/tests/bug48215.phpt
Normal file
38
Zend/tests/bug48215.phpt
Normal file
@ -0,0 +1,38 @@
|
||||
--TEST--
|
||||
Bug #48215 - parent::method() calls __construct
|
||||
--FILE--
|
||||
<?php
|
||||
class A
|
||||
{
|
||||
public function __construct() {
|
||||
echo __METHOD__ . "\n";
|
||||
}
|
||||
protected function A()
|
||||
{
|
||||
echo __METHOD__ . "\n";
|
||||
}
|
||||
}
|
||||
class B extends A
|
||||
{
|
||||
public function __construct() {
|
||||
echo __METHOD__ . "\n";
|
||||
parent::__construct();
|
||||
}
|
||||
public function A()
|
||||
{
|
||||
echo __METHOD__ . "\n";
|
||||
parent::A();
|
||||
}
|
||||
}
|
||||
$b = new B();
|
||||
$b->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===
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user