Re: Type hints with null default values
| From: | Sebastian Bergmann | Date: | Tue, 19 Oct 2004 08:13:58 +0000 |
| Subject: | Re: Type hints with null default values | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-13389@lists.php.net to get a copy of this message | ||
Marcus Boerger wrote:
> Their usage means you can rely on the fact that a certain class type
> or interface is present. That means i could agree to have a way to
> mark typehinted values as optional
I second that. NULL (or anything else than object of the hinted type) is
not an option.
But the ability to declared a typehinted parameter as optional is
something I really need.
In PHPUnit2 I have several occurences of the following workaround:
public function run($result = NULL) {
if ($result === NULL) {
$result = $this->createResult();
}
// XXX: Workaround for missing ability to
// declare type-hinted parameters as optional.
else if (!($result instanceof PHPUnit2_Framework_TestResult)) {
throw new Exception(
'Argument 1 must be an instance of
PHPUnit2_Framework_TestResult.'
);
}
// ...
}
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69