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

From: Date: Fri, 09 Jun 2017 01:35:29 +0000
Subject: Bug #74722 [NEW]: Overridden method with same name as child class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209433@lists.php.net to get a copy of this message
From: mb at iname dot com Operating system: CentOS 6 PHP version: 7.1.6 Package: *General Issues Bug Type: Bug Bug description:Overridden method with same name as child class 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 bug report at https://bugs.php.net/bug.php?id=74722&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74722&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74722&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74722&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=74722&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=74722&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=74722&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=74722&r=needscript Try newer version: https://bugs.php.net/fix.php?id=74722&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=74722&r=support Expected behavior: https://bugs.php.net/fix.php?id=74722&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=74722&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=74722&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=74722&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74722&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=74722&r=dst IIS Stability: https://bugs.php.net/fix.php?id=74722&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=74722&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=74722&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=74722&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=74722&r=mysqlcfg

« previous php.bugs (#209433) next »