What’s difference between __construct and function with same name as class has? [duplicate]

The method named is the PHP4 way of doing a constructor.

For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics.

As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn’t affect non-namespaced classes.

http://www.php.net/manual/en/language.oop5.decon.php

Leave a Comment