 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Giorgio Sironi's Blog: The dangers of Late Static Bindings
by Chris Cornutt April 14, 2010 @ 07:06:41
Giorgio Sironi has a new post that warns you of the dangers that could come from the use of a technology just recently introduced to PHP - late static binding.
There's a lot of (justified) excitement about PHP 5.3 new features, such as the support of namespaces and anonymous functions. Though, some glittering capabilities of the language are definitely not gold: the goto statement is probably the most debated example, but also the long-awaited Late Static Bindings support is an hammer which may hurt your fingers...
He talks about how two of the characteristics of late static binding - the fact that it involves something being static and that there's a sort of hierarchy involved. He gives a code example of how it could be used and notes that static functions should be used sparingly since they are a more procedural way of doing things.
The post also includes a good example - an abstract Factory method - and a bad example - Active Record that doesn't evolve towards a Repository pattern being used.
voice your opinion now!
latestaticbinding danger procedural static hierarchy
Brandon Savage's Blog: A Lesson In Static Methods And Late Static Binding
by Chris Cornutt April 12, 2010 @ 11:10:51
Brandon Savage in his frustrations with the Zend Framework and the "self" keyword in PHP has written up a new post showing how you can use late static binding to work around it.
he problem is, when extended, My_Auth::getInstance() still returns an instance of Zend_Auth. The solution was to duplicate the static method in my My_Auth class, which worked properly. What did I get as a return value? Zend_Auth [...] Why didn't I get an instance of My_Auth instead of Zend_Auth? Well, that's because PHP determines the meaning of the self keyword at compile time, meaning that when you call a function that makes use of it later, you'll get whatever it's been defined to mean when it was compiled.
To remedy the situation he uses late static binding (in PHP 5.3+) by using the "static" keyword like you would use "self" to refer correctly to the current class, not the class it sees at runtime.
voice your opinion now!
static method latestaticbinding lsb method
Jordi Boggiano's Blog: Multiton base class
by Chris Cornutt December 30, 2008 @ 11:17:49
In this recent post Jordi Boggiano looks at a different sort of design pattern - a sort of extension of the Singleton pattern: Multition.
While I like the Singleton pattern every now and then, I prefer the flexibility that the Multiton potentially offers, and well it's just an extended version of the Singleton, so it's "compatible" with the Singleton model. Anyway, to the point, PHP5.3 is coming, and with Late Static Binding you can do a base Multiton (or Singleton if you insist), which wasn't possible before. Now I like this very much because you can simply extend it rather than rewriting those (few, I know, but still) lines each time.
Included in the post is an example of the design pattern showing how to create its structure in the class and use it to grab the same or unique instances (defined with an ID).
voice your opinion now!
multiton base class singleton php5 latestaticbinding lsb
Mike Lively's Blog: Late Static Binding (LSB) forward_static_call()
by Chris Cornutt April 09, 2008 @ 11:24:19
On his blog, Mike Lively has posted a look at some of the work he's been doing on patches for the late static binding functionality to be included in PHP, including an example of the updates in action.
This weekend I wrapped up a few small tests and sent the patch in and it was subsequently pushed to php 5.3 and php 6.0. Now, this is not at all the way I wanted things to work, in all honesty I think the patch is pretty hokey but unfortunately nobody really spoke up in support of the changes I wanted to make to parent:: in regards to LSB.
His example shows how to override a static method and push that new method's execution to the parent class (in two ways - safe using forward_static_call and the not so safe calling itself with a parent:: override).
voice your opinion now!
latestaticbinding php5 php6 patch safe unsafe parent forwardstaticcall
Gergely Hodicska's Blog: What's new in PHP 5.3 - part 1 namespaces
by Chris Cornutt November 14, 2007 @ 12:50:00
Gergely Hodicska has started a mini-series of posts centering about what's going to be coming in the next major release of PHP, version 5.3. The first article has been posted today focusing on one of the more popular topics - namespaces.
In my previous post I mentioned that PHP 5.3 will be released in early 2008 so I think it's just in time to talk about the features of this version. [...] The big gun features are namespaces, late static binding and mysqlnd, but there are other interesting improvements, for example __callStatic, dynamic static calls. In this part of this series we are going to analyze namespaces in detail.
Included in the post are a "before" and "after" example of namspacing in a PHP application, code examples of namespaces in action, simple porting of current PHP 5.2 applications up to 5.3 and working with __autoload and Reflection.
voice your opinion now!
namespace php5 callstatic latestaticbinding tutorial namespace php5 callstatic latestaticbinding tutorial
|
Community Events
Don't see your event here? Let us know!
|