NavigationUser login |
Lack of proper class method overloading is holding PHP back
The lack of proper class method overloading as found in other languages like Java and C# is holding back PHP's development as a first class language and leading to very clunky code.
Here is an example based on Zend Framework 2's Zend\Tag\Item class:
public function __construct($options)
{
if ($options instanceof \Zend\Config\Config) {
$options = $options->toArray();
}
if (!is_array($options)) {
throw new Exception\InvalidArgumentException('Invalid options provided to constructor');
}
$this->setOptions($options);
}
And here is how it should look:
public function __construct(\Zend\Config\Config $options)
{
$this->__construct($options->toArray());
}
public function __construct(array $options)
{
$this->setOptions($options);
}
The latter is so much more elegant but sadly it is not going to work in PHP any time soon. The real question is why?
|
Recent blog posts
|