behrk2 Posted January 23, 2009 Share Posted January 23, 2009 Hey everyone, So I have two classes, let's call them classA and classB. In classA, I instantiate a new object of classB (I have a require_once of classB.php): $cb = new classB(); Now, I call a series of functions from classB: $cb -> functionA(); $cb -> functionB(); $cb -> functionC(); So, let's say functionC() returns a variable, $err, how can I get that returned variable? I know that I can't just say: echo "$cb"; Does anyone know how I can do it? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/142106-solved-question-about-classes/ Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 $foobar = $cb -> functionC(); echo $foobar; Quote Link to comment https://forums.phpfreaks.com/topic/142106-solved-question-about-classes/#findComment-744233 Share on other sites More sharing options...
printf Posted January 23, 2009 Share Posted January 23, 2009 If it returns a variable, then it's... echo $cb->functionC(); Quote Link to comment https://forums.phpfreaks.com/topic/142106-solved-question-about-classes/#findComment-744234 Share on other sites More sharing options...
Maq Posted January 23, 2009 Share Posted January 23, 2009 echo $cb -> functionC(); *** Beaten to it, twice! *** Quote Link to comment https://forums.phpfreaks.com/topic/142106-solved-question-about-classes/#findComment-744235 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 The function has to return a value class myClass{ function functionC() { return "Return This!"; } } $class = new myClass(); $return = $class->functionC(); echo $return; If it does not return a value you will not be able to do that, unless the value is stored as a public property. Quote Link to comment https://forums.phpfreaks.com/topic/142106-solved-question-about-classes/#findComment-744237 Share on other sites More sharing options...
behrk2 Posted January 23, 2009 Author Share Posted January 23, 2009 Thanks for the quick responses everyone, I appreciate it. That did it! I feel so stupid... Quote Link to comment https://forums.phpfreaks.com/topic/142106-solved-question-about-classes/#findComment-744239 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.