OO php: static and factory classes

Kirk Cerny kirksemail at gmail.com
Fri Aug 31 15:43:42 MDT 2007


I thought you called static with the scope oporator

$countImages = ClassName::imageCount ($client_id, $db, __LINE__, __FILE__);


On 8/31/07, Charles Curley <charlescurley at charlescurley.com> wrote:
> I'd like to build a factory class (all static methods) called Images
> that will that create, store, etc. instances of another class,
> Image. I can create image and Images, but I have to instantiate Images
> in order to call a factory method. This works:
>
>
> $snark = new Images ();
> $countImages = $snark->imageCount ($client_id, $db, __LINE__, __FILE__);
>
>
> but this does not:
>
> $countImages = $Images->imageCount ($client_id, $db, __LINE__, __FILE__);
>
> The docs say the second should work:
>
>   Declaring class members or methods as static makes them accessible
>   without needing an instantiation of the class. A member declared as
>   static can not be accessed with an instantiated class object (though
>   a static method can).
>
> http://www.php.net/manual/en/language.oop5.static.php
>
> Relevant code:
>
>
> // The factory class for the image class.
> class Images
> {
>
> ...
>
>     public static function imageCount ($client, $db, $line, $file)
>     {
>
>
> PHP verson is Version 5.1.4.
>
> Thanks
>
> --
>
> Charles Curley                  /"\    ASCII Ribbon Campaign
> Looking for fine software       \ /    Respect for open standards
> and/or writing?                  X     No HTML/RTF in email
> http://www.charlescurley.com    / \    No M$ Word docs in email
>
> Key fingerprint = CE5C 6645 A45A 64E4 94C0  809C FFF6 4C48 4ECD DFDB
>
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
>
>



More information about the PLUG mailing list