News Feed
Sections

News Archive
PHP in Action:
Public constructors considered harmful
May 05, 2008 @ 10:21:33

According to the PHP in Action blog, public constructors can be hazardous to your (application's) health and should be replaced.

Everybody who writes object-oriented code knows about constructors. You need them so the program knows how to instantiate objects, right? And you especially need them when a lot of things have to be done while instantiating an object. [...] So why would I be skeptical of public constructors?

The solution, as he sees it, is to make a "constructor" that's actually called statically with parameters that returns an instance of the class it's in as well as performing the action. He argues that this can help make the code much more readable for some types of method calls.

0 comments voice your opinion now!
public constructor harmful replace private instance



Similar Posts

Matthew Weir O'Phinney's Blog: Extending Singletons

DevShed: Protecting PHP 5 Class Data with Member Visibility

PHPImpact Blog: Static Factories vs Public Constructors

Matthew Weir O'Phinney's Blog: Extending Singletons

The Bakery: Clear the PHP4 warnings when working in eclipsePHP


Community Events











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


zend developer code package book releases PHP5 example application release security mysql conference ajax framework PEAR zendframework cakephp job database

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