rockinaway Posted October 4, 2007 Share Posted October 4, 2007 How can I check if a function has been called? Quote Link to comment https://forums.phpfreaks.com/topic/71859-checking-if-a-function-has-been-called/ Share on other sites More sharing options...
MmmVomit Posted October 4, 2007 Share Posted October 4, 2007 You could set a global variable, but I'm not sure why you would want to do this. What exactly are you trying to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/71859-checking-if-a-function-has-been-called/#findComment-361947 Share on other sites More sharing options...
marcus Posted October 4, 2007 Share Posted October 4, 2007 function test(){ echo "hello"; } if(function_exists('test')){ echo "Test function exists"; }else { echo "Test function does not exist"; } Quote Link to comment https://forums.phpfreaks.com/topic/71859-checking-if-a-function-has-been-called/#findComment-361960 Share on other sites More sharing options...
MmmVomit Posted October 4, 2007 Share Posted October 4, 2007 That will give us whether the function exists. He's asking for whether the function has been called. <?php function foo_called() { // if foo has been called return true, else false } function foo() { // do nothing } foo_called(); // false foo(); foo_called(); // true ?> Quote Link to comment https://forums.phpfreaks.com/topic/71859-checking-if-a-function-has-been-called/#findComment-361965 Share on other sites More sharing options...
rockinaway Posted October 4, 2007 Author Share Posted October 4, 2007 What the situation is is that this is a class function: $class->function() I want to check in my config file if that has been called on the current page, and if it hasn't been called then I want to return an error.. But if it has been called then no error shall be shown and the page will continue. My config file is required in every page so it should check in every page.. however it is required before all the content.. And how does that work MmmVomit.. you have nothing in the functions :S Quote Link to comment https://forums.phpfreaks.com/topic/71859-checking-if-a-function-has-been-called/#findComment-361969 Share on other sites More sharing options...
MmmVomit Posted October 4, 2007 Share Posted October 4, 2007 My code was just to demonstrate what you meant to mgallforever. It's completely non-functional. If the function is in a class, set a private member variable within the class from within the function. I don't know the syntax for class very well, but it would look something like this. <?php class foo { private $init_called = false; function init() { $init_called = true; \\ do more stuff } function initialized() { return $init_called; } } ?> Again, I don't really use classes very much in PHP, so that syntax probably has tons of errors. Quote Link to comment https://forums.phpfreaks.com/topic/71859-checking-if-a-function-has-been-called/#findComment-361975 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.