Edit report at https://bugs.php.net/bug.php?id=40880&edit=1

 ID:                 40880
 Updated by:         ras...@php.net
 Reported by:        prometheus__0 at hotmail dot com
 Summary:            public->protected inheritance causes fatal
 Status:             Not a bug
 Type:               Bug
 Package:            Class/Object related
 Operating System:   SUSE SLES 10
 PHP Version:        5CVS-2007-03-21 (snap)
 Block user comment: N
 Private report:     N

 New Comment:

Most (all?) object oriented languages work this way. Java and C# both do. You 
can 
loosen visibility when you override a parent method, but you can never tighten 
it. This is part of what is known as the Liskov Substitution Principle and it 
is 
one of the fundamental principles of object oriented programming. You can read 
about at http://en.wikipedia.org/wiki/Liskov_substitution_principle

I can guarantee that abiding by LSP is not a bug


Previous Comments:
------------------------------------------------------------------------
[2012-05-06 15:40:26] ekincigokan at gmail dot com

Same "problem".

class A{
    public function __construct(){}
}

class B extends A {
    protected function __construct(){}
}

Please, can you tell us a reason why we can't put an private/protected access 
to B's constructor if A's constructor is public ?
Is there any logical reason to this ?


Thanks.

------------------------------------------------------------------------
[2011-09-10 22:27:24] herman dot wetherington at gmail dot com

Apparently, we don't call this a "bug" because this is not caused by a 
programming error. So I'm calling it a "massive design flaw" instead.

------------------------------------------------------------------------
[2010-10-15 23:33:35] robertoblanko at gmail dot com

Same problem here. You cannot actually apply the singleton pattern to 
subclasses with this behavior. I do not see any reason for not calling this a 
bug.

------------------------------------------------------------------------
[2010-09-07 12:58:35] nickyla83 at yahoo dot fr

I'm in the same situation as our friend "prometheus" here, I am trying to use a 
singleton pattern and logically, this should involve being able to encapsulate 
the subcalasses information particularly setting up a private constructor for 
the singleton subclass, IT DEFINITELY DOES MAKE SENSE, so please try to take 
this under consideration for the next php engine release.

------------------------------------------------------------------------
[2007-03-21 10:05:25] prometheus__0 at hotmail dot com

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?

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=40880


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=40880&edit=1

Reply via email to