|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-07-05 23:37 UTC] aarondoom at cookiedoom dot com
Description:
------------
When a parent document requires a source file and then requires a second file that requires the same as above it cannot access the functions in the already required file from the parent, but cannot use or redefine the functions that are required.
Using code that "if (!defined("_FUNCS_INC_")) { define("_FUNCS_INC_", true); function Bleh($Bloop) { return $Bloop; } } // _FUNCS_INC_".
This is a problem because the _FUNCS_INC_ is defined as well as the functions defined inside of the scope of the document though function_exists will return false and calling the function will obviously fail for that reason, I cannot redefine those functions in the sub-document or I'll get "Cannot redefine function bleh"... even though I can't use it.
Though it is easy enough to work around the issue (With the "if (!defined())" stuff require_once doesn't even make it work BTW) I'm reorganizing several hundred files, at least 1/3 of which are includes which need to be re-ordered.
Any help would be greatly appreciated.
Reproduce code:
---------------
<?php // Funcs.inc
if (!defined("_FUNCS_INC_")) {
define("_FUNCS_INC_", true);
function Bleh() { printf("Blah\n"); }
} // _FUNCS_INC_
?>
<?php // DB.inc
require("Funcs.inc");
Bleh();
?>
<?php // Header.inc
require("Funcs.inc");
require("DB.inc");
Bleh(); // Won't error
?>
Expected result:
----------------
Blah\n
Blah\n
Actual result:
--------------
Fatal error: Call to undefined function: bleh() in /var/www/localhost/includes/DB.inc on line 3
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 26 04:00:02 2025 UTC |
Here's an update to the code, this reproduces the "Bug". <?php // Test.php require("Header.inc"); Bleh(); ?> <?php // Header.inc require("Funcs.inc"); require("Emails.inc"); Bleh(); // Won't error ?> <?php // Funcs.inc if (!defined("_FUNCS_INC_")) { define("_FUNCS_INC_", true); require("DB.inc"); function Bleh() { printf("Blah\n"); } } // _FUNCS_INC_ ?> <?php // Emails.inc if (!defined("_EMAILS_INC_")) { define("_EMAILS_INC_", true); require("DB.inc"); } // _EMAILS_INC_ ?> <?php // DB.inc if (!defined("_DB_INC_")) { define("_DB_INC_", true); require("Funcs.inc"); Bleh(); } // _DB_INC_ ?>