Re: RFC: Type hinting revisited for PHP 5.3
| From: | Hannes Magnusson | Date: | Thu, 02 Jul 2009 10:56:01 +0000 |
| Subject: | Re: RFC: Type hinting revisited for PHP 5.3 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-44634@lists.php.net to get a copy of this message | ||
On Thu, Jul 2, 2009 at 11:24, Ionut G. Stan<ionut.g.stan@gmail.com> wrote:
> Hi,
>
> I'm a userland developer with limited C skills, and while I don't yet have
> an
> opinion on the whole type enforcing issue, aside from a fear of libraries
> abusing
> it, I'd like to propose a little change in the patch.
>
> Is it possible that instead of an E_RECOVERABLE_ERROR, an Exception to
> be thrown? I don't know whether InvalidArgumentException satisfies the
> semantics,
> but it's a step in that direction.
<?php
function throw_exception($errno, $errmsg) {
if (strpos($errmsg, "Argument ") === 0) {
throw new InvalidArgumentException($errmsg, $errno);
}
return false;
}
set_error_handler("throw_exception", E_RECOVERABLE_ERROR);
function foo(array $arr) {}
foo("string");
Here you go.
-Hannes