Bug #72496 [NEW]: Cannot declare public method with signature incompatible with parent private me
From: postmaster at greg0ire dot fr
Operating system: Linux
PHP version: 5.5.37
Package: Class/Object related
Bug Type: Bug
Bug description:Cannot declare public method with signature incompatible with parent private me
Description:
------------
When declaring a public method in a child class, one can't reuse the
name of a private method of the parent without being issued a Warning
for php 7, a Strict Standards error for php 5.5 - 5.6, unless the
signature is considered compatible.
Test script:
---------------
<?php
class Foo
{
private function getName()
{
return 'John';
}
}
class Bar extends Foo
{
public function getName($extraArgument)
{
return $extraArgument;
}
}
Demonstration : https://3v4l.org/SNlDO
Expected result:
----------------
The parent method is private : it can't be called from the outside and
as far as the child class is concerned, it does not exist. Creating a
public method with the same name is not overriding the method since
methods in the parent class will still call the private method when
asked to.
Actual result:
--------------
php 7.7 : Warning: Declaration of Bar::getName($extraArgument) should be
compatible with Foo::getName() in /in/SNlDO on line 17
5.5.0 - 5.6.22 : Strict Standards: Declaration of Bar::getName() should
be compatible with Foo::getName() in /in/SNlDO on line 17
--
Edit bug report at https://bugs.php.net/bug.php?id=72496&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72496&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72496&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72496&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72496&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72496&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72496&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72496&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72496&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72496&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72496&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72496&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72496&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72496&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72496&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72496&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72496&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72496&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72496&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72496&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72496&r=mysqlcfg
Thread (6 messages)
- postmaster at greg0ire dot fr