Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPBuilder.com:
Three Advanced Object-Oriented PHP Features You Need to Know
Jun 16, 2010 @ 14:13:23

On PHPBuilder.com there's a new article on OOP in PHP applications, specifically some of the things that PHP5 has to offer you if you're not using it to its fullest potential.

I'll introduce you to three of PHP's advanced object-oriented features which seem to not have garnered the attention they deserve. The topics discussed here should be useful whether you're a relative newcomer to object-oriented development and are looking to expand your knowledge, or have a background using languages such as Java or C# and are trying to learn more about what PHP has to offer.

These three things he introduces are Reflection (PHP's API for introspection of code), the SPL (Standard PHP Library) set of objects and tools and a more recent addition - late static binding.

tagged: objectoriented oop php5 feature spl reflection latestaticbinding

Link:

Giorgio Sironi's Blog:
The dangers of Late Static Bindings
Apr 14, 2010 @ 12: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.

tagged: latestaticbinding danger procedural static hierarchy

Link:

Brandon Savage's Blog:
A Lesson In Static Methods And Late Static Binding
Apr 12, 2010 @ 16: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.

tagged: static method latestaticbinding lsb method

Link:

Jordi Boggiano's Blog:
Multiton base class
Dec 30, 2008 @ 17: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).

tagged: multiton base class singleton php5 latestaticbinding lsb

Link:

PHP.net:
PHP 5.3 alpha 1 Released
Aug 01, 2008 @ 12:58:29

As announced on the PHP.net site today, the first alpha version of the much-anticipated PHP 5.3 has been released - PHP 5.3 alpha 1.

The PHP development team is proud to announce the first alpha release (Windows binaries will appear in the next few days) of the upcoming minor version update of PHP. The new version PHP 5.3 is expected to improve stability and performance as well as add new language syntax and extensions. Several new features have already been documented in the official documentation, others are listed on the wiki in preparation of getting documented. Please also review the NEWS file.

Among the list of new features/improvements are things like namespaces, late static binding, lambda functions, closures, support for mysqlnd and removal of support for pre-Windows 2000 systems. For more information on when the full stable version will his the web, check out the release plan.

tagged: php5 release alpha preview namespace latestaticbinding lambda closures

Link:

Mike Lively's Blog:
Late Static Binding (LSB) forward_static_call()
Apr 09, 2008 @ 16: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).

tagged: latestaticbinding php5 php6 patch safe unsafe parent forwardstaticcall

Link:

Antony Dovgal's Blog:
5.3 snapshots are available
Feb 28, 2008 @ 15:33:00

Antony Dovgal points out that Derick Rethans has added the snapshots for PHP 5.3 to the snaps.php.net website.

Short list of what you can find there: Namespaces, __callstatic() magic method, accessing static members through $foo::myFunc(), fully rewritten ini-parser with .htaccess-like user defined ini files for CGI/FastCGI, improved OpenSSL extension, PCRE 7.4, and other fixes and improvements that will never get into 5_2 branch.

He recommends teching throughly before the major release to find all of the bug before the general public does. Builds for both source and Windows systems have been posted.

tagged: php5 snapshot snaps namespace latestaticbinding static pcre openssl

Link:

Mike Lively's Blog:
Late Static Binding - Changes to parent
Nov 26, 2007 @ 15:37:00

Mike Lively has shared some of his thoughts on the late static binding functionality that will be in the upcoming PHP 5.3 - specifically the relationships of parents and children it has.

I won't rehash all of the arguments as you can quite easily find out my full thoughts by previous posts and on that mailing list thread. To put it simply I feel that somehow there needs to be a way to call methods in a parent class without losing the ability to reference back to the original called static.

He gives an example of what he's talking about (code) and, to help further his cause he's created three patches to make it work how he'd like.

tagged: latestaticbinding parent change child patch latestaticbinding parent change child patch

Link:

Mike Lively's Blog:
Late Static Binding - Changes to parent
Nov 26, 2007 @ 15:37:00

Mike Lively has shared some of his thoughts on the late static binding functionality that will be in the upcoming PHP 5.3 - specifically the relationships of parents and children it has.

I won't rehash all of the arguments as you can quite easily find out my full thoughts by previous posts and on that mailing list thread. To put it simply I feel that somehow there needs to be a way to call methods in a parent class without losing the ability to reference back to the original called static.

He gives an example of what he's talking about (code) and, to help further his cause he's created three patches to make it work how he'd like.

tagged: latestaticbinding parent change child patch latestaticbinding parent change child patch

Link:

Gergely Hodicska's Blog:
What is new in PHP 5.3 - part 2: late static binding
Nov 15, 2007 @ 13:57:00

Gergely Hodicska has posted part two of his look at the upcoming PHP 5.3 release. In his previous post, he looked at namespacing, but in this new one he covers late static binding (mor einfo here).

In the second part we will deal with static late binding, which is a very exciting new feature in PHP 5.3 and which promise some really nifty code. :) This topic attracted attention after Zend Framework. There was a little outcry in the PHP blogosphere, that the ActiveRecord examples presented in this webcast can't work in PHP even with the version 5.2. Now with late static binding it is possible to implement this style of ActiveRecord almost correctly.

His post is an example of implementing the ActiveRecord (sort of) pattern, complete with code examples.

tagged: php5 latestaticbinding activerecord implement php5 latestaticbinding activerecord implement

Link:


Trending Topics: