ID: 40880
User updated by: prometheus__0 at hotmail dot com
Reported By: prometheus__0 at hotmail dot com
Status: Bogus
Bug Type: Class/Object related
Operating System: SUSE SLES 10
PHP Version: 5CVS-2007-03-21 (snap)
New Comment:
is this the 'php'-dev definition?
i'm asking cause wraping a singleton pattern around a subclass makes
sense
and the same example is valid for java and c++
to ask it differently: why is it working this way in php? (i'm
interested in the background of this)
my point is that 2 languages allow it and there is an example which is
valid, not?
Previous Comments:
------------------------------------------------------------------------
[2007-03-21 09:43:47] derick@php.net
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
This is how it works... you can always open up an API through a new
extended interface, but not hide more.
------------------------------------------------------------------------
[2007-03-21 09:38:19] prometheus__0 at hotmail dot com
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 this bug report at http://bugs.php.net/?id=40880&edit=1