php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #55375 Inherited constructor signature: new behavior of PHP5.4 or bug?
Submitted: 2011-08-06 11:02 UTC Modified: 2018-12-30 16:55 UTC
Votes:7
Avg. Score:4.3 ± 1.4
Reproduced:5 of 7 (71.4%)
Same Version:1 (20.0%)
Same OS:1 (20.0%)
From: mikaelkael@php.net Assigned: girgias (profile)
Status: Closed Package: Class/Object related
PHP Version: >= 5.4.0 OS: N/A
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
1 + 26 = ?
Subscribe to this entry?

 
 [2011-08-06 11:02 UTC] mikaelkael@php.net
Description:
------------
I just experiment this behavior with PHP5.4a3 when running the following code:
    <?php
    abstract class Zend_Pdf_FileParserDataSource
    {
        abstract public function __construct();
    }

    class Zend_Pdf_FileParserDataSource_File extends Zend_Pdf_FileParserDataSource
    {
        public function __construct($filePath)
        {}
    }

    $test = new Zend_Pdf_FileParserDataSource_File('path');

    // Throw a Fatal Error:
    /*
    PHP Fatal error: Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with that of Zend_Pdf_FileParserDataSource::__construct() in /home/mikaelkael/php54.php on line 11

    Fatal error: Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with that of Zend_Pdf_FileParserDataSource::__construct() in /home/mikaelkael/php54.php on line 11
   */

It throws a fatal error (like a "normal" class method in 5.3). But this code was OK for the constructor in 5.3. In case of new behavior, is it possible to document it? I can't find any informations in NEWS or in UPGRADE files.

Test script:
---------------
<?php
abstract class Zend_Pdf_FileParserDataSource
{
    abstract public function __construct();
}

class Zend_Pdf_FileParserDataSource_File extends Zend_Pdf_FileParserDataSource
{
    public function __construct($filePath)
    {}
}

$test = new Zend_Pdf_FileParserDataSource_File('path');

// Throw a Fatal Error:
/*
PHP Fatal error: Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with that of Zend_Pdf_FileParserDataSource::__construct() in /home/mikaelkael/php54.php on line 11

Fatal error: Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with that of Zend_Pdf_FileParserDataSource::__construct() in /home/mikaelkael/php54.php on line 11
*/


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-06 15:51 UTC] pajoye@php.net
It sounds to me like a bug fix. As the child declaration is more restrictive than 
the parent declaration, and is against any good design or OO convention.
 [2011-08-06 15:52 UTC] felipe@php.net
-Status: Open +Status: To be documented
 [2011-08-06 15:52 UTC] felipe@php.net
In fact the behavior has been changed in 5.4, related to bug #51421.
I'll add the change to UPGRADING file, thanks.
 [2011-08-06 15:58 UTC] perraud dot mickael at orange dot fr
Perfect, thanks!
 [2012-10-26 16:29 UTC] dagguh at gmail dot com
Abstract constructors? What are you smoking? WONTFIX
 [2016-03-27 16:45 UTC] nikic@php.net
-Type: Bug +Type: Documentation Problem
 [2018-12-30 16:55 UTC] girgias@php.net
-Status: Open +Status: Closed -Operating System: Debian Squeeze +Operating System: N/A -PHP Version: 5.4.0alpha3 +PHP Version: >= 5.4.0 -Assigned To: +Assigned To: girgias
 [2018-12-30 16:55 UTC] girgias@php.net
Seems more like bad code design than a documentation error.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC