WhiteyDude Posted April 3, 2007 Share Posted April 3, 2007 Note: I don't think anyone checks the O.O.P. section... There arn't many posts or reads there... It's fine if someone wants to delete the original topic there . Hi guys, I have a quick but relatively urgent question. I have 2 classes here, and I wish to call a function that's inside one of them from another. Example code: Main page: <?php $class1 = new Class1(); $class2 = new Class2(); $class1->function1(); ?> Class 1 <?php class Class1 { function Class1() {} function function1() { //THIS is the line I'm having a problem with Class2::class2function(); } } ?> Class 2 <?php class Class2 { function Class2() {} function class2function() { echo "Worked!"; } } ?> Another problem is that on the apache server I'm running (2.2.4, local) I'm unable to display PHP errors. I've tried everything I can think of - the PHP ini is starting to get worn, it's been modified so many times. PHP 5.2.1 by the way. Please help guys, I need this fixed within the next hour or so. Thanks, /Whitey Quote Link to comment Share on other sites More sharing options...
btherl Posted April 3, 2007 Share Posted April 3, 2007 You need to include() or require() your class definitions inside your main file. After that, the code works perfectly. For example: require_once('class1.php'); require_once('class2.php'); Quote Link to comment Share on other sites More sharing options...
WhiteyDude Posted April 3, 2007 Author Share Posted April 3, 2007 I forgot to put that into the example code I put up there... They're both required, they're both initialized fine. I can't call class2function() from inside Class1 still though.. /Whitey Quote Link to comment Share on other sites More sharing options...
btherl Posted April 3, 2007 Share Posted April 3, 2007 Please post your actual code, not just an "example". Your example works fine. Quote Link to comment 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.