Having a function defined in commons.php
desktop.php -> include commons.php
|
|
\|/
include MODULES.'mod.php'
I can call my custom function anywhere I want, but not inside an exit that’s inside an if. The code where calling the function won’t go:
Mod.php:
....
$error = mysql_error();
if($_ADM['id_user']==1) {
if(!empty($error)) {
$debug = array(
'message' => "SQL Error in infography_edit module.",
'line' => '79',
'error' => $error,
'SQL' => $SQL
);
//exit(myPrint($debug)); //Calling here myPrint does not work
exit(print_r($debug)); //This works
}
}
$test = array('alex');
exit(myPrint($debug)); //Calling here myPrint works
....
// The output error: Call to undefined function myPrint()
I just can’t understand why anywhere else outside the code above works, but not inside it without defining it again inside
UPDATE
Doing it this way, doesn’t seem to work either:
myPrint($debug);
exit();
// The output error: Call to undefined function myPrint()
UPDATE2
desktop.php the main file:
- require(LIBS.’commons.php’);
- common html
- include module
Codepad containing desktop’s code: http://codepad.org/hn8QlHQ9
Ok, first of all I have to clarify that the code I was working on, wasn’t mine, I was just hired to make some improvements and had to talk to the main developer to explain that chaos.
What I kept missing is that every request (every single one that had to do with a page refresh) was going through a secondary file called
do.phpwhich eventually loaded the module that I was at, again.Visual explication:
Now, just so you know, current module location (
http://site.com/module?=add_users) is saved in a session anddo.phphas a few lines of code to check that session and include back the module if everything ok. I know it’s a huge mess, but I can’t do nothing about it.So, eventually I had to go to
do.phpand add this following line around the beginning of the file:require_once('libs/commons.php');My recommendation
Whenever you see that a function doesn’t load, but you know it loads perfectly in certain cases, look for any other file that might interfere as
do.phpdoes above, and try including/requiring the file that contains the function.I know things like those can give headaches, but it is what it is and most of the time is not our fault, but the way the platform was already written.
Good luck to all