Bug #74722 [Com]: Overridden method with same name as child class

From: Date: Fri, 09 Jun 2017 01:41:12 +0000
Subject: Bug #74722 [Com]: Overridden method with same name as child class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209434@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74722&edit=1 ID: 74722 Comment by: mail at pmmaga dot net Reported by: mb at iname dot com Summary: Overridden method with same name as child class Status: Open Type: Bug Package: *General Issues Operating System: CentOS 6 PHP Version: 7.1.6 Block user comment: N Private report: N New Comment: What you are seeing is the result of your method b() in class b being used as a constructor for it. See: http://php.net/manual/en/language.oop5.decon.php for more info Previous Comments: ------------------------------------------------------------------------ [2017-06-09 01:35:27] mb at iname dot com Description: ------------ The example below produces a fatal error: Fatal error: Call to protected b::b() from invalid context in test.php on line 17 Changing visibility of child's method to public results in b::b() being invoked twice (prints 'ChildChild'). Renaming the child class to anything but 'b' resolves the issue. Test script: --------------- <?php class a { protected function b() { echo 'Parent'; } public function test() { $this->b(); } } class b extends a { protected function b() { echo 'Child'; } } $o = new b(); $o->test(); Expected result: ---------------- The script should print "Child". Alternatively, if methods with same name as class are not allowed, the script should fail at parsing stage. Actual result: -------------- Fatal error: Call to protected b::b() from invalid context in test.php on line 17 If b::b() is set public in child, prints 'ChildChild' ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74722&edit=1

« previous php.bugs (#209434) next »