#48215 [Asn->Csd]: Child calling parent::func calls constructor instead of method (BC break!)
| From: | mark at everytruckjob dot com | Date: | Sat, 11 Jul 2009 19:15:59 +0000 |
| Subject: | #48215 [Asn->Csd]: Child calling parent::func calls constructor instead of method (BC break!) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-139628@lists.php.net to get a copy of this message | ||
ID: 48215
User updated by: mark at everytruckjob dot com
Reported By: mark at everytruckjob dot com
-Status: Assigned
+Status: Closed
Bug Type: Class/Object related
Operating System: *
PHP Version: 5.3, 6CVS (2009-05-09)
Assigned To: scottmac
New Comment:
Seems to be fixed in PHP 5.3 release.
Previous Comments:
------------------------------------------------------------------------
[2009-05-10 18:10:53] 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-05-09 21:59:42] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48215&edit=1