NYCPHP Meetup

NYPHP.org

[nycphp-talk] OOP Question: Calling a classes function from another class

Andy Dirnberger dirn at dirnonline.com
Wed Apr 18 10:05:13 EDT 2007


Something along these lines might work for you:

class Error {
  public static function Log (param1, param2, 
) {
    

  }
}




Error::Log (value1, value2, 
);

> Hello Again, 
> 
> I've been porting my PHP4 libs to PHP5 OO, and I thus I have no formal OOP
training.
> This is my crash course.
>
> So, I've created an error logging class, 
> 
> class Error
> and I want to call it from another class.
> Is it necessary to create another instance of the class?
> 
> I tried to use the Error:Log("error", log_level) (Calling form the Class
Utility)
> way of calling the function, but the Log( ) function
> using $this->someOtherFunction and this is being mistaken for the parent
Class (Utility->someOtherFunction) not the Error class.
> 
> So, do I have to create a new instane of the object?
> 
> Is there any way to create the object in the constructor of the other
class,
> and then pass it around and call it when I need it via
$this->OBJECT->function?
> 
> Thanks!
> 
> - Ben
 




More information about the talk mailing list