php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49177 include() causes strict erros when including overloading methods (PHP_5_2 only!)
Submitted: 2009-08-06 12:03 UTC Modified: 2010-08-12 23:59 UTC
Votes:7
Avg. Score:4.1 ± 0.6
Reproduced:6 of 7 (85.7%)
Same Version:4 (66.7%)
Same OS:6 (100.0%)
From: ss at zornig dot dk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
 [2009-08-06 12:03 UTC] ss at zornig dot dk
Description:
------------
When overloading a method, changing a parameter to accept a default value  E_STRICT error is triggered. This however only happens if the object declaration is loading using include, not if the declaration is in the file called.

Reproduce code:
---------------
test.php:
<?php
error_reporting(E_ALL | E_STRICT);

abstract class ObjParent {
	public function set($param1, $param2){ }
}

require_once('obj.php');
?>

obj.php:
<?php
class ObjChild extends ObjParent {
	public function set($param1, $param2=true){ }
}
?>


Expected result:
----------------
This should be without any errors as i would if the test.php looks like this:

<?php
error_reporting(E_ALL | E_STRICT);

abstract class ObjParent {
	public function set($param1, $param2){ }
}

class ObjChild extends ObjParent {
	public function set($param1, $param2=true){ }
}
?>

Actual result:
--------------
Strict Standards: Declaration of ObjChild::set() should be compatible with that of ObjParent::set() in /home/webroot/dumpsite/obj.php on line 8

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-20 13:39 UTC] ss at zornig dot dk
Description:
------------
This works in 5.3.2 however, I have found a similar error.

Reproduce code:
---------------
test.php:
<?php
error_reporting(E_ALL | E_STRICT);

abstract class ObjParent {
	public function set(ObjParent $param1, $param2){ }
}

require_once('obj.php');
?>

obj.php:
<?php
class ObjChild extends ObjParent {
	public function set(ObjChild $param1, $param2=true){ }
}
?>



Expected result:
----------------
This should be without any errors as i would if the test.php looks like this:

<?php
error_reporting(E_ALL | E_STRICT);

abstract class ObjParent {
	public function set(ObjParent $param1, $param2){ }
}

class ObjChild extends ObjParent {
	public function set(ObjChild $param1, $param2){ }
}
?>

Actual result:
--------------
Strict Standards: Declaration of ObjChild::set() should be compatible with that of ObjParent::set() in /usr/home/webroot/dumpsite/bug/obj.php  on line 4
 [2010-04-20 13:40 UTC] ss at zornig dot dk
-PHP Version: 5.2 (SVN-2009-08-05) +PHP Version: 5.*
 [2010-04-20 13:40 UTC] ss at zornig dot dk
I have found a similar error in 5.3.2
 [2010-08-12 23:59 UTC] stas@php.net
-Status: Verified +Status: Bogus
 [2010-08-12 23:59 UTC] stas@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You example restricts first parameter from ObjParent to ObjChild. making child function accept only subset of arguments that parent function accepts. This is a violation of LSP, of which the warning warns.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 17:01:30 2025 UTC