php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51867 include() causes strict erros when including overloading methods
Submitted: 2010-05-20 09:26 UTC Modified: 2010-05-20 10:58 UTC
From: ss at zornig dot dk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: FreeBSD 7.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ss at zornig dot dk
New email:
PHP Version: OS:

 

 [2010-05-20 09:26 UTC] ss at zornig dot dk
Description:
------------
When overloading a method, changing a object type hint to accept a child class instead a E_STRICT error is triggered. This however only happens if the object declaration is loaded using include, not if the declaration is in the file called.


Test script:
---------------
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-20 09:33 UTC] mike@php.net
It should actually always case an E_STRICT, as you force a more specific method signature which is strictly speaking incompatible.
 [2010-05-20 10:18 UTC] ss at zornig dot dk
It looks like it is 100% my bad, however i should change the bug description then? But maybe it should trigger a fatal error then?
 [2010-05-20 10:53 UTC] johannes@php.net
If you put all in one file the error is triggered during compilation, before error_reporting() is executed. You have to change your error reporting settings in php.ini.

And no it is an strict error as it is no real problem for the engine but an hint for you to write better code.
 [2010-05-20 10:58 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-05-20 10:58 UTC] johannes@php.net
.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun May 04 12:01:28 2025 UTC