From: prometheus__0 at hotmail dot com
Operating system: SUSE SLES 10
PHP version: 5CVS-2007-03-21 (snap)
PHP Bug Type: Class/Object related
Bug description: public->protected inheritance causes fatal
Description:
------------
(1) It is not possible to make inherited functions more private, which
seems like a bug to me but
(2) it is possible to make inherited functions more public, which
shouldn't be possible, afaik.
The example code causes the fatal (1)
if you change
protected function __construct()
to
public function __construct()
from class b
and
public function __construct(){
to
protected function __construct(){
from class a
it works (2)
since i'm not an expert in oop i tried the same example in java and it
works the complete opposite way (the b functions can be more private but
not more public)
and in C++ it's the same
i know bug report http://bugs.php.net/bug.php?id=34237 but it considers
point (2)
point (1) is still a bug in my opinion
Reproduce code:
---------------
<?php
class a{
public function __construct(){
print("public construct\n");
}
}
class b extends a{
protected function __construct(){
print("protected construct\n");
}
public static function getInstance(){
return new b();
}
}
$b = b::getInstance();
?>
Expected result:
----------------
protected construct
Actual result:
--------------
Fatal error: Access level to b::__construct() must be public (as in class
a) in PHPDocument2 on line 16
--
Edit bug report at http://bugs.php.net/?id=40880&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=40880&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=40880&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=40880&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40880&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=40880&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40880&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40880&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40880&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40880&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40880&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=40880&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=40880&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40880&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40880&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40880&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40880&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40880&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40880&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40880&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40880&r=mysqlcfg