Re: Declaration of Bar::__construct() must be compatible
| From: | Ferdinand Beyer | Date: | Thu, 26 Feb 2004 10:09:23 +0000 |
| Subject: | Re: Declaration of Bar::__construct() must be compatible | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-8163@lists.php.net to get a copy of this message | ||
IMO we are trying to force a strict programming here that is
incompatible with PHP's loose character.
The following example for instance is very common in Java AVT
programming:
<?php
class Window {
function __construct($title)
{
}
}
class MyApplicationWindow extends Window
{
const VERSION = "1.1";
function __construct()
{
parent::__construct("My Application v." . self::VERSION");
}
}
?>
Furthermore with the new implementation we disallow "the PHP way
for overloaded methods" using a variable parameter count:
<?php
class Base
{
function doSomething(MyClass $obj)
{
}
}
class Extended extends Base
{
function doSomething()
{
$args = func_get_args();
switch (count($args)) {
case 0:
return parent::doSomething(new MyClass());
case 1:
if ($args[0] instanceof MyClass) {
return parent::doSomething($args[0]);
}
return parent::doSomething(new MyClass($args[0]));
default:
throw new IllegalArgumentException();
}
}
}
?>
--
Ferdinand Beyer
<fb@fbeyer.com>