Ninjakreborn Posted March 29, 2010 Share Posted March 29, 2010 I have a debug class within portable_framework.php. <?php class Debug { function print_multiple($title, $array, $title2 = 'empty', $array2 = array(), $title3 = 'empty', $array3 = array(), $title4 = 'empty', $array4 = array()) { echo $title.'<br />'; echo '<pre>'; print_r($array); echo '</pre>'; echo '<br />'; if ($title2 != 'empty') { echo $title2.'<br />'; echo '<pre>'; print_r($array2); echo '</pre>'; echo '<br />'; } if ($title3 != 'empty') { echo $title3.'<br />'; echo '<pre>'; print_r($array3); echo '</pre>'; echo '<br />'; } if ($title4 != 'empty') { echo $title4.'<br />'; echo '<pre>'; print_r($array4); echo '</pre>'; echo '<br />'; } } } $debug = new Debug(); ?> This is a very simple test case to prove my point. I have this portable_framework.php included at the top of my master file..results.php. In results.php right after the require of that class file it let's me access that class. I have another file called "link_parser.php" that is included in the results.php further down. This is setup to allow me to cut my code up some so it's not all in one place. Here is hte issue. I can't access my Debug class inside hte link_parser.php at all. It's like the class being required into the results.php is accessible there, but not in other files that are included later on. Is that normal, and if so is there a way I can include a class file and have it work throughout the entire system..even if there are a few levels of includes? Quote Link to comment https://forums.phpfreaks.com/topic/196892-strange-behaviour-with-class/ Share on other sites More sharing options...
Ninjakreborn Posted March 29, 2010 Author Share Posted March 29, 2010 By the way, I mis-told you on part of that. I can access it in those other files, just not inside of functions. This is related to scope. Is there a way I can make that class global. SO it'll be usable in and out of any functions. I may want to throw a few debug calls right inside of other functions that are dealing with loops and it's ignoring that..I don't want to have to pass my class by reference to every function or it'll just defeat the purpose of the time I am trying to save. IS this possible? Quote Link to comment https://forums.phpfreaks.com/topic/196892-strange-behaviour-with-class/#findComment-1033669 Share on other sites More sharing options...
ignace Posted March 29, 2010 Share Posted March 29, 2010 A class in PHP is always global you can access it - once declared - everywhere. Quote Link to comment https://forums.phpfreaks.com/topic/196892-strange-behaviour-with-class/#findComment-1033714 Share on other sites More sharing options...
Zane Posted March 29, 2010 Share Posted March 29, 2010 Is your question about the Debug class (that you generously posted) or is it about an include problem, because reading and re-reading your situation isn't doing anything for me except confuse me. Just from my understandings... you are trying to include a file with a class in it.. and then include that file (including the class) into another file... and use the class.. Or are you trying to pass an object around? Quote Link to comment https://forums.phpfreaks.com/topic/196892-strange-behaviour-with-class/#findComment-1033729 Share on other sites More sharing options...
jcbones Posted March 29, 2010 Share Posted March 29, 2010 class link_parser { function __construct() { $this->debug = new Debug(); } } Edit: Proof reading, makes you less of an idiot. :doh: Quote Link to comment https://forums.phpfreaks.com/topic/196892-strange-behaviour-with-class/#findComment-1033831 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.