News Feed
Sections




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

Stubbles Blog:
My wishlist for PHP6, pt4 static initializers
March 26, 2007 @ 09:16:00

In a continuation of their "wishlist" series of posts for PHP6, Stephan Schmidt has postted this new item today taking about something he wishes PHP could do - initialize a property when defining an object.

But how could this be solved, when you never create an instance of Foo but only use static method calls?

I propose a new feature, we implemented in the Stubbles class loader and has been shamelessly ripped from the XP framework. If you need to initialize some properties with objects and are developing with Stubbles, you only need to implement a method called __static() in your class. If your class is loaded by the Stubbles class loader, it will check, whether this method has been implemented and call it. As every class is only loaded once, this enables you to add code to your class, that is also only executed once, if the class is imported into your application.

His solution allows for the creation of such objects with little more than the use of a __static call that could get the object and change the property defined on it.

1 comment voice your opinion now!
static initializers php6 wishlist class loader static initializers php6 wishlist class loader


blog comments powered by Disqus

Similar Posts

PHPImpact Blog: Static Factories vs Public Constructors

DevShed: Using Subclasses and Accessors with Member Visibility to Protect PHP 5 Class Data

Till's Blog: Nginx+PHP+FastCGI: Testing your web application with bleeding edge PHP

C7Y: Late Static Binding: a practical example

International PHP Magazine: Poll - Which One of the Following Should a PHP Programmer Give Priority?


Community Events





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


introduction version community interview tool series framework update package install composer opinion language laravel podcast voicesoftheelephpant symfony library release security

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