php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2918 require doesn't work like described in manual
Submitted: 1999-12-05 15:29 UTC Modified: 1999-12-05 16:08 UTC
From: django at informatik dot uni-tuebingen dot de Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.12 OS: Redhat Linux 6.0 (intel)
Private report: No CVE-ID: None
 [1999-12-05 15:29 UTC] django at informatik dot uni-tuebingen dot de
Hi!

Look at the following 3 files:

::::::::::::::
a.phtml
::::::::::::::
<?
require("b.phtml");

function my_function_a() {
print "I'm function a!<P>\n";
my_function_b();
return true;
}

?>
::::::::::::::
b.phtml
::::::::::::::
<?
function my_function_b() {
print "I'm function b!<P>";
return true;
}
?>
::::::::::::::
main.phtml
::::::::::::::
<?
require("a.phtml");
require("b.phtml");

my_function_a();

my_function_b();

?>


If you 'start' main.phtml in the browser via WWW-server you'll get the following error message:
Fatal error: Can't redeclare already declared function in b.phtml on line 5

As described in the manual (and IMO) require should handle 'main.phtml' in the following way:
- Replace 'require("a.phtml")' with the content of 'a.phtml'. Then 'main.phtml' should look like followed:

<?
require("b.phtml");

function my_function_a() {
print "I'm function a!<P>\n";
my_function_b();
return true;
}
require("b.phtml");

my_function_a();

my_function_b();

?>

As described in the manual PHP should handle ONLY the first occurence of 'require("b.phtml")' and ignore the second occurence. But PHP seems not to detect this, if the 'require' command is split over several files, all direct or indirect included (with 'require') into the main file.

Am I wrong or is this a bug?

Please send me an email, if you need more information.

Thanks in advance

Steffen Wieschalla

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-12-05 16:08 UTC] rasmus at cvs dot php dot net
Nowhere in the manual does it say that require will ignore a second require of the same file.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 10:00:02 2026 UTC