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! 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; 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(); 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! *** 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. 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... Link to comment https://forums.phpfreaks.com/topic/142106-solved-question-about-classes/#findComment-744239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.