A Lesson In Static Methods And Late Static Binding

Until last week, I had never experienced what must have been incredibly frustrating to most developers: the fact that the self keyword in PHP refers to the class it is located in, and not necessarily a class that extends it. I personally ran into this problem when trying to extend Zend_Auth. Being a singleton, the constructor in Zend_Auth is protected, and the static method Zend_Auth::getInstance() instantiates itself. The 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. For example:


(more…)

Monday, April 12th, 2010 @ 7:00 am | Comment (4) | Categories: Object-Oriented Development, PHP 5, Technology, Zend Framework
Tags: , , , ,


Copyright © 2022 by Brandon Savage. All rights reserved.