Cannot call function inside exit ()

Having a function defined in commons.php

 desktop.php -> include commons.php | | \|/ include MODULES.'mod.php' 

I can call my custom function anywhere, but not inside the output, which is inside the if. The code calling the function will not 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

Running this method doesn't seem to work either:

 myPrint($debug); exit(); // The output error: Call to undefined function myPrint() 

UPDATE2

desktop.php main file:

  • required (LIBS.'commons.php ');
  • shared html
  • enable module

Codepad containing desktop code: http://codepad.org/hn8QlHQ9

+4
source share
5 answers

Well, first of all, I have to clarify that the code I was working on was not mine, I was just hired to make some improvements and I had to talk to the main developer to explain this chaos.

What I missed is that each request (each of which was associated with a page refresh) went through an additional file called do.php , which eventually loaded the module I was in again.

Visual Explication:

 Currently at Action Pre-Processor Processor ------------- => --------------- => ------------- => --------- add_users.php post from form do.php add_user.php 

Now, just now you know, the current location of the module ( http://site.com/module?=add_users ) is saved in the session, and do.php has several lines of code to check this session and turn the module back on, if everything is ok . I know this is a huge mess, but there is nothing I can do about it.

So in the end I had to go to do.php and add the following line around the beginning of the file: require_once('libs/commons.php');

My recommendation

Whenever you see that a function does not load, but you know that it loads fine in certain cases, look for any other file that might interfere with do.php above and try to include / require a file containing the function.

I know that such things can give headaches, but this is what it is, and most of the time it is not our fault, but how the platform was already written.

Good luck everyone

0
source

like a workaround like

 function my_exit($msg){ echo $msg; exit(1); //Return code of the script, useful for cli scripts } //... my_exit("Show message"); //... 
+1
source

Your code should work, assuming that your conditional criteria are met.

Function call undefined myPrint ()

The above error indicates that the myPrint() function is not defined. You can use the function_exists () function to check if any function has completed. If it does not exist, you can override it in the current context.

 <?php if (function_exists('myPrint')) { echo "myPrint() exists.\n"; } else { echo "myPrint() doesn't exist.\n"; } ?> 
0
source

exit() is a language construct capable of accepting only scalar values ​​of type int and string . If you need to print something before exiting the script, I suggest you do this before calling exit.

 .... $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 ); myPrint($debug); exit(); .... 
0
source

Do you accidentally use namespaces? Are you sure your function is defined? If it is on, are you sure you turned it on?

PS RobB is sorry to tell you, but it really works.

Example:

 $v = 1234; function xyz($v){ echo $v . 23; } exit( xyz($v) ); 
0
source

All Articles