#48376 [Opn->Bgs]: Method scope demotion allowed from private scope grandparent
| From: | johannes@php.net | Date: | Sun, 24 May 2009 17:58:53 +0000 |
| Subject: | #48376 [Opn->Bgs]: Method scope demotion allowed from private scope grandparent | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137684@lists.php.net to get a copy of this message | ||
ID: 48376
Updated by: johannes@php.net
Reported By: kev dot simpson at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: Windows XP Home
PHP Version: 5.2.9
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
We decided to do less strict checking on the constructor. So this is
the way it is meant to be.
Previous Comments:
------------------------------------------------------------------------
[2009-05-24 17:14:07] kev dot simpson at gmail dot com
Description:
------------
Tested in 5.2.5, 5.2.9-2 and 6.0.0-dev using Apache 5.0.59
When a class uses a private scope on a method, any grandchild class can
demote the scope regardless of what the primary class's immediate child
scope is. Curious if I can exploit this as a feature or if it is indeed
a bug.
Example is in order to help visualize.
Reproduce code:
---------------
<?php
class TestParent
{
private function __construct()
{
}
}
class Child extends TestParent
{
public function __construct() // Ok, parent is private and
unviewable, so not technically overridding
{
printf("%s\n", __CLASS__);
}
}
class GrandChild extends Child
{
protected function __construct() // Override here; scope reduction
is prohibited in PHP
{
parent::__construct();
printf("%s\n", __CLASS__);
}
public static function createInstance()
{
return new self;
}
}
GrandChild::createInstance();
?>
Expected result:
----------------
I expect this to produce a fatal error indicating that 'Access level to
GrandChild::__construct() must be public (as in Child) in ....'
Actual result:
--------------
Child
GrandChild
Returning of object of instance GrandChild.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48376&edit=1