Bug #72496 [Com]: Cannot declare public method with signature incompatible with parent private me
| From: | postmaster at greg0ire dot fr | Date: | Tue, 28 Jun 2016 12:52:54 +0000 |
| Subject: | Bug #72496 [Com]: Cannot declare public method with signature incompatible with parent private me | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-201886@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72496&edit=1
ID: 72496
Comment by: postmaster at greg0ire dot fr
Reported by: postmaster at greg0ire dot fr
Summary: Cannot declare public method with signature
incompatible with parent private me
Status: Verified
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 5.5.37
Block user comment: N
Private report: N
New Comment:
> Right. LSP should not be enforced when overriding private methods.
Clearly. As a side note, this only happens if the method in the child class is public or protected.
Previous Comments:
------------------------------------------------------------------------
[2016-06-28 11:23:59] nikic@php.net
Right. LSP should not be enforced when overriding private methods.
------------------------------------------------------------------------
[2016-06-26 17:18:04] postmaster at greg0ire dot fr
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 this bug report at https://bugs.php.net/bug.php?id=72496&edit=1