Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.