Bug #61970 [Opn]: Restraining __construct() access level in subclass gives a fatal error

From: Date: Mon, 07 May 2012 18:47:00 +0000
Subject: Bug #61970 [Opn]: Restraining __construct() access level in subclass gives a fatal error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-170290@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61970&edit=1

 ID:                 61970
 User updated by:    postmaster at greg0ire dot fr
 Reported by:        postmaster at greg0ire dot fr
-Summary:            Restraining __constructor() access level in subclass
                     gives a fatal error
+Summary:            Restraining __construct() access level in subclass
                     gives a fatal error
 Status:             Open
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Linux
 PHP Version:        5.3.12
 Block user comment: N
 Private report:     N

 New Comment:

fixed the title


Previous Comments:
------------------------------------------------------------------------
[2012-05-07 18:40:56] postmaster at greg0ire dot fr

Description:
------------
Restraining the __construct() method un a subtype gives a Fatal error.
As stated in the following resources, the LSP should not apply here.


- https://bugs.php.net/bug.php?id=40880
- http://stackoverflow.com/questions/5490824/should-constructors-comply-with-the-liskov-substitution-principle
- http://ralphschindler.com/2012/03/09/php-constructor-best-practices-and-the-prototype-pattern

Test script:
---------------
<?php

class Foo {
    public function __construct(){}
}

class Bar extends Foo {
    protected function __construct(){}
}

Expected result:
----------------
No output at all.

Actual result:
--------------
> PHP Fatal error:  Access level to Bar::__construct() must be public (as in class Foo) in
> /tmp/bug.php on line 9

> Fatal error: Access level to Bar::__construct() must be public (as in class Foo) in
> /tmp/bug.php on line 9


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



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


Thread (8 messages)

« previous php.bugs (#170290) next »