From:             
Operating system: Linux
PHP version:      5.3.12
Package:          Class/Object related
Bug Type:         Bug
Bug description:Restraining __constructor() access level in subclass gives a 
fatal error

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 bug report at https://bugs.php.net/bug.php?id=61970&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=61970&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=61970&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=61970&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=61970&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=61970&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=61970&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=61970&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=61970&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=61970&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=61970&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=61970&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=61970&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=61970&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=61970&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=61970&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=61970&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=61970&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=61970&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=61970&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=61970&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=61970&r=mysqlcfg

Reply via email to