Re: Scalar Type Hints v0.4
| From: | Patrick ALLAERT | Date: | Wed, 18 Feb 2015 22:13:37 +0000 |
| Subject: | Re: Scalar Type Hints v0.4 | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83128@lists.php.net to get a copy of this message | ||
Le Wed Feb 18 2015 at 18:35:02, François Laupretre <francois@php.net> a
écrit :
> > De : Patrick ALLAERT [mailto:patrickallaert@php.net]
> > ini_set("coercion_reporting", COERCION_ERROR); // Fail in case of
> > potentially bad coercion
> >
> > foo(7);
> > // int(7)
> > foo("7");
> > // int(7)
> > foo("7 dogs");
> > // Catchable fatal error: Unsafe coercion transforming "7 dogs" to
> "7".
> >
> > The biggest advantage, IMHO, is that you get the exact same result
> whether
> > you do:
> >
> > foo((int) $value);
> >
> > or:
> >
> > foo($value);
> >
> > ... whatever the mode you are in.
> >
> > Basically, this is weak type hints + something similar to what I
> > contributed in the past with the "Array to string conversion" notice
> (see:
> > https://github.com/php/php-src/commit/d81ea16e).
> >
> > Care to share the pro's/con's you see with a solution like that?
>
> That's a good idea, IMO. We can add an optional message when a conversion
> is executed in ZPP macros. It can help. The main drawback is that it is
> pure runtime check, not suitable for static analysis and related tools.
>
Does it sounds like a "compromise"? ;)
More seriously, I'm not sure that should be a prerequisite for accepting an
RFC.
Patrick