Patterns For PHP
Moderator: General Moderators
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Patterns For PHP
Been aiming to put this up during the Summer, but then someone suggested a PHP Book project and I decided just to get it done.
Since it will likely be used for some later book contributions, I'm just throwing it out there for discussion and possible contributions. It's a wiki, not unlike http://phppatterns.com which will be a repository of patterns specifically implemented for PHP.
http://patterns.quantum-star.com (dedicated domain to come)
Have added the Singleton and Registry patterns as a small start. I am converting a prior blog post on the Factory and Abstract Factory patterns. Public submissions are welcome as detailed on the front page with any texts made available to the PHP Book project with any other contributions on design patterns which are sure to pour in over time.
Since it will likely be used for some later book contributions, I'm just throwing it out there for discussion and possible contributions. It's a wiki, not unlike http://phppatterns.com which will be a repository of patterns specifically implemented for PHP.
http://patterns.quantum-star.com (dedicated domain to come)
Have added the Singleton and Registry patterns as a small start. I am converting a prior blog post on the Factory and Abstract Factory patterns. Public submissions are welcome as detailed on the front page with any texts made available to the PHP Book project with any other contributions on design patterns which are sure to pour in over time.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Good idea. Phppatterns.com has been out of date for a very long time -- and honestly it wasn't that great to start with.
I really like that you have shown two example of implementing the pattern for a real use case -- instead of just creating eponymous classes
PS - I checked out the Singleton. As I recall the PHP4 version is better if you assign as $thisInstance[0] = new Settings(); because of something about static vars in PHP4 -- but I can't rememeber what.
I really like that you have shown two example of implementing the pattern for a real use case -- instead of just creating eponymous classes
PS - I checked out the Singleton. As I recall the PHP4 version is better if you assign as $thisInstance[0] = new Settings(); because of something about static vars in PHP4 -- but I can't rememeber what.
(#10850)
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
If either of you want write access just give me a shout. Any contributions would be welcome. It's closed just for the moment until I fix up a domain for it and then public access will be enabled. The texts are still initial drafts - there'll likely be other small errors until I get around to reviewing them all this evening.
I'll look into that static var issue for PHP - is this specific to any version range?
Factory Pattern added to the mix...
I'll look into that static var issue for PHP - is this specific to any version range?
Factory Pattern added to the mix...
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
I'll setup an account for you and send you a PM. This is intended as a public wiki, so if you have an idea - go with it.
I also intend to include at some point a section on the principles behind design patterns, since its highly relevant material and explains a lot about how and why patterns exist, i.e. coding to an interface, polymorphism, decoupling, etc. For the moment the pattern section is seeing attention mainly - but feel free to expand.
Also the current texts are initial drafts - they are intended to be elaborated upon over time hopefully in a format which offers a simplified overview/summary followed by more in depth detail. At present I'm just following a standard section order to get the initial text setup. Unit Tests for the patterns are also intended.
I natter on
.
I also intend to include at some point a section on the principles behind design patterns, since its highly relevant material and explains a lot about how and why patterns exist, i.e. coding to an interface, polymorphism, decoupling, etc. For the moment the pattern section is seeing attention mainly - but feel free to expand.
Also the current texts are initial drafts - they are intended to be elaborated upon over time hopefully in a format which offers a simplified overview/summary followed by more in depth detail. At present I'm just following a standard section order to get the initial text setup. Unit Tests for the patterns are also intended.
I natter on
actually $thisInstance[0] =& new Settings;arborint wrote: PS - I checked out the Singleton. As I recall the PHP4 version is better if you assign as $thisInstance[0] = new Settings(); because of something about static vars in PHP4 -- but I can't rememeber what.
Due to the fact that a static can't hold a reference, but an element of a static array can.
http://www.php.net/manual/en/language.v ... references
Oh, and thank goodness I don't have to mess around with all those ampersands any more in PHP5 (unless I really mean if for pass by ref in functions).
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
This is an interesting point, because I remember pulling my hair out over this a long while back. I use few singletons but since that exercise I usually drop the ampersand reference character (hence the example's form). I amended the PHP 4 example and added a short explanation and link to the above part of the manual.Due to the fact that a static can't hold a reference, but an element of a static array can.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I was thinking about doing something similar in the last few weeks. The basic idea I had was to walk through the PoEAA and GoF books (to start) and build most, if not all, of those patterns into PHP variants. Although I'm interested to help, I don't know about the time I'd need to write and document these patterns.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
A MediaWiki version of the repository is now being spruced up:
http://www.quantum-star.com/mediawiki/
http://www.quantum-star.com/mediawiki/
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
And now finished (I think). Back at http://patterns.quantum-star.com .