News Feed
Sections




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

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.

1 comment voice your opinion now!
public constructor harmful replace private instance


blog comments powered by Disqus

Similar Posts

Tim Koschuetzki's Blog: Composing Methods: Substitute Algorithmn

Anthony Ferrara's Blog: IteratorIterator - PHP Inconsistencies And WTFs

Hasin Hayder: Install and Run Symfony 2.3.6 projects in OpenShift instances in just one minute

Wojciech Sznapka's Blog: Accessing private object property from other object in PHP

Stefan Koopmanschap's Blog: public static vs static public


Community Events

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


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

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