From: kev dot simpson at gmail dot com Operating system: Windows XP Home PHP version: 5.2.9 PHP Bug Type: Class/Object related Bug description: Method scope demotion allowed from private scope grandparent
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 bug report at http://bugs.php.net/?id=48376&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48376&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48376&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48376&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=48376&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48376&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=48376&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=48376&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=48376&r=needscript Try newer version: http://bugs.php.net/fix.php?id=48376&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=48376&r=support Expected behavior: http://bugs.php.net/fix.php?id=48376&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=48376&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=48376&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=48376&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48376&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=48376&r=dst IIS Stability: http://bugs.php.net/fix.php?id=48376&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=48376&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=48376&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=48376&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=48376&r=mysqlcfg