News Feed
Sections




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

Brandon Savage's Blog:
A Lesson In Static Methods And Late Static Binding
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.

0 comments voice your opinion now!
static method latestaticbinding lsb method


blog comments powered by Disqus

Similar Posts

The Bakery: Some ideas to organize your CSS files and autoload them in CakePHP

Padraic Brady's Blog: Zend Framework Caching (Parts 1, 2 & 2b)

Jose da Silva's Blog: Revisiting PHP 5.3 __invoke magic method

DevShed: Object-Oriented Programming Through Design Patterns

DevShed: Generating Outputs from MySQL with Static Members and Methods in PHP 5


Community Events

Don't see your event here?
Let us know!


interview release performance laravel php7 symfony2 configure conference community opinion api framework application example podcast introduction library install series voicesoftheelephpant

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework