The reasoning in the accepted answer is wrong.
I find renaming classes to be a bad practice: things can get tangled when using Reflection or complex dependence structure like PHP frameworks often do. It also break dependencies regardless of the constructor syntax. As a rule of thumb:
- if the class name conflicts, use namespaces
- if the class name sucks, use Decorator pattern or inheritance
- if the class has to be adapted to the project, use Adapter pattern
Java, C++ or C# don't use __construct
, they use named constructor and there's no issue with them. PHP is, however, a different story:
1. PHP 5.3.3 removed named constructors in namespaces
2. PHP 7.0 deprecated all named constructors
3. PHP 8.0 removed all named constructors
So named constructors are no longer an option. But to answer your question:
the reason for the deprecation/removal named constructors is probably that PHP functions/methods are case insensitive, so in legacy PHP code there was this problem:
class Filter {
function filter() {
echo "this is a constructor, not a method!";
}
}
// so you could never write
// $filter = new Filter;
// $filter->filter();
This is the official PHP RFC reasoning behind the removal of named constructors.
Funnily, PHP variables are case sensitive, there's little reasoning in PHP development, see this funny legacy official PHP 4.0 release announcement.