php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50897 Require() problem with E_STRICT
Submitted: 2010-02-01 10:20 UTC Modified: 2010-02-01 13:58 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: frederic dot hardy at mageekbox dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID: None
 [2010-02-01 10:20 UTC] frederic dot hardy at mageekbox dot net
Description:
------------
Require() and include() are more strict than a all in one file then parse php code.

Reproduce code:
---------------
file a.php
<?php

class a { public function test($fool) {} }

?>

file b.php
<?php

class b { public function test($foo, $bar) {} }

?>

file withRequire.php
<?php

error_reporting(E_STRICT);

require('a.php');
require('b.php');

$b = new b();

?>

file allInOne.php
<?php

error_reporting(E_STRICT);

class a { public function test($foo) {} }
class b [ public function test($foo, $bar) {} }

$b = new b();

?>

Expected result:
----------------
In CLI, "php withRequire.php" must give same result than php "allInOne.php".

Actual result:
--------------
php allInOne.php => nothing
php withRequire.php => Strict standards: Declaration of b::test() should be compatible with that of a::test() in /path/to/b.php on line 8


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-01 10:30 UTC] frederic dot hardy at mageekbox dot net
the "b" class must extends the "a" class, all my apologize.
 [2010-02-01 11:59 UTC] jani@php.net
Not sure what's going on here, but this is the difference eventually:

No E_STRICT notice:
<?php

error_reporting(E_STRICT);

class a{function test($foo){}}
class b extends a{function test($foo, $bar){}}

$b = new b();

?>

E_STRICT notice
<?php

error_reporting(E_STRICT);

class b extends a{function test($foo, $bar){}}
class a{function test($foo){}}

$b = new b();

?>

 [2010-02-01 12:08 UTC] mvalleton at sauf dot ca
The problem isn't related with the order in which you declare classes a and b:

The warning appears when classes a and b are declared in the *correct* order, but in a different file, and then required by the main script.

Here is a simple example: http://ssz.fr/brdl/php-bug-50897.tbz2

classes.php:
<?php
class a {public function test($foo) {}}
class b extends a {public function test($foo, $bar) {}}
?>

script.php:
<?php
error_reporting(E_STRICT);
require "classes.php";
$b = new b();
?>
 [2010-02-01 12:19 UTC] jani@php.net
Yes, but the order should not matter, that was my point. :)
 [2010-02-01 12:21 UTC] jani@php.net
And the notice should be output in all cases..
 [2010-02-01 12:27 UTC] frederic dot hardy at mageekbox dot net
Why the notice should be output in all cases ?
It's not a problem if b::test() has a signature wich is different from a::test().
If it's a problem, what is the interest of extends b from a, or more globaly, what is the interest of inheritance if you can not override method with different signature ?
 [2010-02-01 13:08 UTC] jani@php.net
If you feel it's a problem, don't put E_STRICT in your error_reporting..
 [2010-02-01 13:29 UTC] frederic dot hardy at mageekbox dot net
lol :).
So there is an another problem, __construct() seems to be not checked like other method...
It seems to me that there is lot of inconsistency with E_STRICT and method signature checking.
 [2010-02-01 13:51 UTC] dmitry@php.net
A class in PHP may be declared at compile time or at run time. As result the warning is also emitted at compile or run time. It's clear that compile time declarations aren't affected by error_reporting() function and use setting from php.ini.

So in your examples the error isn't lost, but just hidden by settings in your php.ini.
 [2010-02-01 13:58 UTC] frederic dot hardy at mageekbox dot net
I'm confirm that.
With error level set to E_STRICT in php.ini, the warning is displayed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 06:01:38 2025 UTC