NYCPHP Meetup

NYPHP.org

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

Ben Sgro (ProjectSkyline) ben at projectskyline.com
Wed Apr 18 11:37:41 EDT 2007


Hello Brian,

Thanks, that's what I did.

$this->Error->function( ... );

Works great.

Thanks to everyone.

I just went to order the book on bookpool.com, but its out of stock.
I'll wait a bit and get it soon. Thanks.

- Ben

----- Original Message ----- 
From: "Brian Dailey" <support at dailytechnology.net>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Wednesday, April 18, 2007 10:03 AM
Subject: Re: [nycphp-talk] OOP Question: Calling a classes function from 
anotherclass


> If you're just starting out in the PHP5 OOP world, I highly recommend
> Zandstra's "PHP 5 Objects, Patterns, and Practice." I promise you it's
> worth the $20.
>
> If you need it in the entire class, you could create a new instance of
> the object in the __construct function ($this->Error = new Error) and
> then use it later. Either that or you could make it static and call it
> throughout the program (assuming that fits your needs).
>
> - Brian
>
> Ben Sgro (ProjectSkyline) wrote:
>> 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
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> New York PHP Community Talk Mailing List
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>> NYPHPCon 2006 Presentations Online
>> http://www.nyphpcon.com
>>
>> Show Your Participation in New York PHP
>> http://www.nyphp.org/show_participation.php
>
> -- 
>
> Thanks!
> - Brian Dailey
> Software Developer
> New York, NY
> www.dailytechnology.net
>


--------------------------------------------------------------------------------


> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php 




More information about the talk mailing list