php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48215 Child calling parent::func calls constructor instead of method (BC break!)
Submitted: 2009-05-09 21:59 UTC Modified: 2009-07-11 19:15 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: mark at everytruckjob dot com Assigned: scottmac (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.3, 6CVS (2009-05-09) OS: *
Private report: No CVE-ID: None
 [2009-05-09 21:59 UTC] mark at everytruckjob dot com
Description:
------------
Child class calling parent::function calls parent's php4 style constructor of same name instead of parent's public method named the same as the class.

Reproduce code:
---------------
<?php
class search  
{
    public function __construct()  
    {
        echo "<br>".__METHOD__;
    }
    protected function search()
    {
        echo "<br>".__METHOD__;
    }
}
class search2 extends search  
{
    public function __construct()            
    {
        echo "<br>".__METHOD__;
        parent::__construct();     
    }
    public function search()   
    {
        echo "<br>".__METHOD__;
        parent::search();
    }
}

$search2 = new search2();
$search2->search();
?>

Expected result:
----------------
search2::__construct
search::__construct
search2::search
search::__search


Actual result:
--------------
search2::__construct
search::__construct
search2::search
search::__construct


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-10 18:10 UTC] jani@php.net
Not sure if this is actually intentional change in PHP_5.3 (and HEAD) 
but this is different from PHP_5_2:

[jani@linux5 ~]$ /usr/src/build/php_5_2CVS_FCGI/sapi/cli/php -n -d 
error_reporting="E_ALL | E_STRICT"  t.php

Strict Standards: Redefining already defined constructor for class 
search in /home/jani/t.php on line 9
search2::__construct()
search::__construct()
search2::search()
search::search()

[jani@linux5 ~]$ /usr/src/build/php_5_3CVS_FCGI/sapi/cli/php -n -d 
error_reporting="E_ALL | E_STRICT"  t.php

Strict Standards: Redefining already defined constructor for class 
search in /home/jani/t.php on line 9
search2::__construct()
search::__construct()
search2::search()
search::__construct()

 [2009-07-11 19:15 UTC] mark at everytruckjob dot com
Seems to be fixed in PHP 5.3 release.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC