Jump to content

Function access from within an included file


lxndr

Recommended Posts

I've inherited some php scripts and one of them is generating an error.  The scripts are quite large but in essence the problem is being caused by the following in that script1.php which is loaded into index.php via an "include" statement in turn tries to access a function within index.php itself and subsequently generates an error that the function has not been declared.  Is there a recommended way to fix this?

 

 

Simplified scenario:

 

index.php

 

<?
include("script1.php")

function update_log()
   {

   }

$var = function2();


?>

 

 

 

script1.php

 

<?
function2()
{
update_log();
}
?>

 

 

 

 

 

Link to comment
Share on other sites

There's nothing technically wrong what you have shown and the simplified example works (after you fix the few syntax errors in it.)

 

Best guess is that the include statement is failing or the use of the short open tags is causing the code to not be seen as php code or you have a spelling error between the names being used...

 

Are you debugging this on a system with error_reporting set to E_ALL and display_errors is set to ON so that php would report and display all the errors it detects?

 

You would need to show the actual code and the actual error (the file and line number helps track down what is happening) to get the quickest solution without wasting a lot of time guessing which of the dozen possible reasons is causing the problem.

Link to comment
Share on other sites

Thanks for responding to my post.

 

There's nothing technically wrong what you have shown and the simplified example works (after you fix the few syntax errors in it.)

What I showed was merely to illustrate the structure of the scripts as I'm sure you realised, there are no such syntax errors in the actual scripts.

 

 

Best guess is that the include statement is failing or the use of the short open tags is causing the code to not be seen as php code or you have a spelling error between the names being used...

Short open tags are not used in the actual scripts, the content of the include statement is one single function which is used throughout the main index.php script so is not failing.  There are no spelling errors.

 

 

Are you debugging this on a system with error_reporting set to E_ALL and display_errors is set to ON so that php would report and display all the errors it detects?

Yes to both the above.

 

 

You would need to show the actual code and the actual error (the file and line number helps track down what is happening) to get the quickest solution without wasting a lot of time guessing which of the dozen possible reasons is causing the problem.

I'm not in a position to share the actual code but thanks for your suggestions anyway.

 

__

 

Link to comment
Share on other sites

Cannot help you with your actual problem then.

 

Due to the general purpose nature of programming, 113 different people could have written your tread in this forum with the same symptom and there could be something different wrong in each of their programs.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.