Jump to content

How to call to method from other Class at the same time


lilmer

Recommended Posts

I've got a class method that is working fine on my localhost but when I included on the website im working on it aint working, and I see that the site only requires static call.

I use to call like this, and this is working fine:

$result = $this->Class->method(0);

$result->methodFromAnotherClass();

But on the modified framework that right now I'm using I ain't allowed to use that kind of calling. It must be a static call so I use

$result = Class::method(0);

but when I use to call the other method like:

$result->methodFromAnotherClass();

It give's me an error.

Anyone can suggest how to do it?

if Class::method(0); returns an instance of some result class, which it should so that you can have more than one of them at any time, then using $result->methodFromAnotherClass(); should work.

 

However, since you didn't post the error you got that would have given us actual information about why it didn't work, you are pretty much on you own with that problem.

 

if your question is instead how would you convert $result->methodFromAnotherClass() to a static call, that all depends on what the code is doing. you may need to completely rewrite it to allow for multiple sets of stored properties to support multiple instances of it.

 

in general, using static methods/properties should be avoided, not embraced.

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.