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

Eric Hogue's Blog:
Late Static Binding
Apr 22, 2011 @ 14:14:34

Eric Hogue has a recent post to his blog looking at one of the more tricky aspects of the latest versions of PHP (the 5.3.x series) - late static binding. In a nutshell, late static binding (LSB) lets static classes and methods work more correctly than before. Eric gets into a bit more detail than that:

It came out almost 2 years ago, but it to me that many programmers around me have no idea about it. Myself, I have learned about it around 6 months ago. The PHP documentation defines late static binding as a way to "reference the called class in a context of static inheritance." This definition didn't really help me the first time I read it. Fortunately, there are more explanations in the documentation, and there are good examples. If you haven't, you should read it.

To clarify, he includes a code snippet showing the use of the "static" keyword to correctly reference a static method. He also includes in interesting bit about when's a good time to use it.

tagged: late static binding lsb tutorial explaination

Link:

C7Y:
Late Static Binding: a practical example
Feb 12, 2008 @ 21:52:36

Sean Coates has posted a new article today about one of the features that will be included in the next major release of PHP (5.3) - late static bindings.

Late Static Binding (LSB) is a topic that's been brought up numerous times in the past three years in various PHP development discussion circles (and we're finally getting it in PHP 5.3)—but what does it really do, and why should you care? Here's a simple practical example of how it can greatly simplify your code's design.

He shows its usefulness in an example of how it works, letting classes/objects access static methods, constants and properties of inherited classes (besides their own). His example (using beer, of course) shows how an extended class (Ale) can reference the constant (NAME) in the parent class (Beer). Thanks to a new keyword in PHP 5.3 - "static::" - helps define the difference even clearer.

Check out the rest of the article for a more practical usage too.

tagged: late static binding tutorial example beer

Link:

Mike Lively's Blog:
Late static binding....sorta :/
Sep 27, 2007 @ 17:58:00

Mike Lively is happy about one thing - that late static binding (definition) has been committed and will be included with PHP 5.3. Unfortunately, he has a downside too:

The good news is late static binding has been introduced into head and looks like it will be merged into 5.3 before it is released. The horrible news is I really don't think the patch went as far as it needs to.

He talks about the original intention of the functionality (flexible inheritance for static methods/properties/constants) and how it was implemented, but with one small issue - that "static will ALWAYS return the 'resolved' name of the class used to call the current function". He illustrates with a code example showing an extended class returning a static property.

He also mentions two suggestions to help fix this issue:

  • setting the behavior of parent:: such that it forwards the calling class through the next function call.
  • introducing another scope [...] using a new keyword so parent:: could remain the same
tagged: late static binding patch missing functionality parent inheritance late static binding patch missing functionality parent inheritance

Link:

Mike Lively's Blog:
Late static binding....sorta :/
Sep 27, 2007 @ 17:58:00

Mike Lively is happy about one thing - that late static binding (definition) has been committed and will be included with PHP 5.3. Unfortunately, he has a downside too:

The good news is late static binding has been introduced into head and looks like it will be merged into 5.3 before it is released. The horrible news is I really don't think the patch went as far as it needs to.

He talks about the original intention of the functionality (flexible inheritance for static methods/properties/constants) and how it was implemented, but with one small issue - that "static will ALWAYS return the 'resolved' name of the class used to call the current function". He illustrates with a code example showing an extended class returning a static property.

He also mentions two suggestions to help fix this issue:

  • setting the behavior of parent:: such that it forwards the calling class through the next function call.
  • introducing another scope [...] using a new keyword so parent:: could remain the same
tagged: late static binding patch missing functionality parent inheritance late static binding patch missing functionality parent inheritance

Link:

Etienne Kneuss' Blog:
Late Static Bindings Explained
Sep 07, 2007 @ 19:26:00

Etienne Kneuss has a new article posted about and introducing a feature that will be implemented in PHP6 - late static bindings.

Late Static Binding (LSB, yes, not LSD) is an OO feature that is meant to be implemented in PHP 6, and maybe even backported to PHP 5. This article will describe what LSB is, what problems it's supposed to solve and how. The patch this article talks about can be found here: late_static_bindings_take6.patch

Etienne explains what they are and includes several code examples to show how they'll work. There's also a mention of "edge cases" where special circumstances might cause the script to fall back on the "magic" functions (__get, __post, etc).

tagged: late static binding php6 explain introduction example late static binding php6 explain introduction example

Link:

Etienne Kneuss' Blog:
Late Static Bindings Explained
Sep 07, 2007 @ 19:26:00

Etienne Kneuss has a new article posted about and introducing a feature that will be implemented in PHP6 - late static bindings.

Late Static Binding (LSB, yes, not LSD) is an OO feature that is meant to be implemented in PHP 6, and maybe even backported to PHP 5. This article will describe what LSB is, what problems it's supposed to solve and how. The patch this article talks about can be found here: late_static_bindings_take6.patch

Etienne explains what they are and includes several code examples to show how they'll work. There's also a mention of "edge cases" where special circumstances might cause the script to fall back on the "magic" functions (__get, __post, etc).

tagged: late static binding php6 explain introduction example late static binding php6 explain introduction example

Link:

DevShed:
PHP 5 and Polymorphism
Mar 07, 2006 @ 13:19:08

From DevShed, there's a more advanced tutorial that might interest PHP developers out there looking for more info on "polymorphism" for their apps.

This article explains what polymorphism is and how it applies to object oriented design in particular. It also explains the pros and cons of polymorphism when working with certain versions of PHP.

They start with a definition on the topic that doesn't seem to help much: "The occurrence of different forms, stages, or types in individual organisms or in organisms of the same species, independent of sexual variations." They do, however, follow that with what it means to programming: "...an interface or base class without regard to an object's concrete class." They also include a simple example (no code, that's later).

With that concept in place, they move to the next step - working with the example to create code that can be used as a reference point. They talk about using a switch to make the script respond differently to different inputs and the lack of "late binding" support in PHP5.

tagged: php5 polymorphism late binding switch php5 polymorphism late binding switch

Link:

DevShed:
PHP 5 and Polymorphism
Mar 07, 2006 @ 13:19:08

From DevShed, there's a more advanced tutorial that might interest PHP developers out there looking for more info on "polymorphism" for their apps.

This article explains what polymorphism is and how it applies to object oriented design in particular. It also explains the pros and cons of polymorphism when working with certain versions of PHP.

They start with a definition on the topic that doesn't seem to help much: "The occurrence of different forms, stages, or types in individual organisms or in organisms of the same species, independent of sexual variations." They do, however, follow that with what it means to programming: "...an interface or base class without regard to an object's concrete class." They also include a simple example (no code, that's later).

With that concept in place, they move to the next step - working with the example to create code that can be used as a reference point. They talk about using a switch to make the script respond differently to different inputs and the lack of "late binding" support in PHP5.

tagged: php5 polymorphism late binding switch php5 polymorphism late binding switch

Link:


Trending Topics: