Edit report at https://bugs.php.net/bug.php?id=62814&edit=1
ID: 62814
Comment by: kev dot simpson at gmail dot com
Reported by: resha dot ru at gmail dot com
Summary: It is possible to stiffen child class members
visibility
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 5.3.15
Block user comment: N
Private report: N
New Comment:
I reported this same problem a few years ago here:
https://bugs.php.net/bug.php?id=48376
I was told this was not a bug (although I haven't a clue as to why its not
deemed as such). I believe C# allows you the ability to do this as it would
resolve up the scope, but as of 5.4.0 I still cannot get why it allows forced
reduced scopes during declaration, but provides an uncatchable fatal error on
call.
I'm still most concerned by the allowed reduction from an interface. There is
no way to guarantee that an interface will implement the method in question
regardless of if it is known to be that type which truly is a shame.
Previous Comments:
------------------------------------------------------------------------
[2012-08-14 09:50:47] resha dot ru at gmail dot com
Sorry, it should be:
class F extends D
{
private function test() { } // stiffen visibility from public to private
(unexpected)
}
But nevertheless.
------------------------------------------------------------------------
[2012-08-14 09:48:17] resha dot ru at gmail dot com
Description:
------------
It is possible to stiffen visibility (from public to protected, from public to
private and from protected to private) if any of parent classes has private
modifier.
Test script:
---------------
class A
{
private function test() { }
}
class B extends A
{
protected function test() { } // loosen visibility from private to
protected (expected)
}
class C extends B
{
private function test() { } // stiffen visibility from protected to
private (unexpected)
}
class D extends B
{
public function test() { } // loosen visibility from protected to public
(expected)
}
class E extends D
{
protected function test() { } // stiffen visibility from public to
protected (unexpected)
}
class F extends B
{
private function test() { } // stiffen visibility from public to private
(unexpected)
}
Expected result:
----------------
PHP Fatal error: Access level to C::test() must be protected (as in class B)
or
weaker
Actual result:
--------------
Everything is ok.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62814&edit=1