Re: [RFC] Safe Casting Functions
| From: | Dmitry Stogov | Date: | Wed, 22 Oct 2014 07:45:59 +0000 |
| Subject: | Re: [RFC] Safe Casting Functions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78216@lists.php.net to get a copy of this message | ||
On Wed, Oct 22, 2014 at 2:51 AM, Andrea Faulds <ajf@ajf.me> wrote:
>
> > On 21 Oct 2014, at 10:14, Dmitry Stogov <dmitry@zend.com> wrote:
> >
> > some notes:
> > - it's probably make sense to implement these function as a new
> opcode(s) in VM
>
> That could be an optimisation later, yes. I note that you’ve added
> function replacement with opcodes for certain commonly-used functions. We
> could make these functions use that. Then they’d still be usable as
> callbacks.
>
I may help with implementation, if RFC accepted.
(It would be better if ZEND_STRLEN, ZEND_TYPE_CHECK, etc were introduced in
first place instead of stlen(), is_long() and family).
> > - in case of conversion failure it's better to throw exception (to_int()
> returning FALSE is a pain).
>
> I am gradually warming to throwing an exception. An interesting idea I’ve
> had suggested on Twitter was by Matt Parker, who suggested that I add an
> optional 2nd argument. Without the argument, it throws an exception. With
> an argument, it returns that value (as a default) instead of throwing an
> exception.
>
Together with https://wiki.php.net/rfc/engine_exceptions_for_php7
throwing
exceptions would be the best choice. I would make it permanent, (without
optional areguments)
Thanks. Dmitry.
>
> --
> Andrea Faulds
> http://ajf.me/
>
>
>
>
>