Jump to content

[SOLVED] Question about classes


behrk2

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.