lxndr Posted March 28, 2010 Share Posted March 28, 2010 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(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/196738-function-access-from-within-an-included-file/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 28, 2010 Share Posted March 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196738-function-access-from-within-an-included-file/#findComment-1032858 Share on other sites More sharing options...
lxndr Posted March 28, 2010 Author Share Posted March 28, 2010 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. __ Quote Link to comment https://forums.phpfreaks.com/topic/196738-function-access-from-within-an-included-file/#findComment-1032886 Share on other sites More sharing options...
PFMaBiSmAd Posted March 28, 2010 Share Posted March 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196738-function-access-from-within-an-included-file/#findComment-1032888 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.