[PHP-DEV] Re: [RFC] Nullable Casting

2019-04-21 Thread David Rodrigues
Discussion topic:

- Not 100% needed: is the same that says "nullable typehint is not 100%
need because we can just check in time". This argument has no sense, once
that PHP supports nullable casting for parameters typehint, and the
nullable casting is just a way to fit the argument to parameter typehint
that is already possible, but very hacky ($x !== null ? (string) $x : null
vs. (?string) $x).

- What about e.g. nullable_intval()? intval() is a PHP 4 feature that could
be replaced in 99% of cases by (int) cast. So nullable_intval() make no
sense once that probabily it will be never used (except it (?int) will not
be implemented, but if nullable_intval() could be, so is better (?int)
instead).

- Fallible Casting: it should works exactly as current castings, but with
possibility to be null if it is already null. For instance: (int) "string"
currently will be int (0), by this way, so (?int) "string" should be int
(0) too. The nullable casting will ONLY return NULL if the subject is NULL,
exclusively in this case. So it will affects only (int) null that currently
is int (0). So (?int) null will be null. Same for falsy values: (int) '' is
currently int (0), so (?int) '' will be int (0) also.

- Alternative syntax (null|int): very ugly, no? :P Maybe on future it could
be valid for multicasting eg. (string|int|float) $x, but this is subject to
another topic.

- A cast where you can't be sure of what you'll get back: you will have the
same sure that currently you have with (int) $x, with exception that
nullable values are more explicit because "if $x is null, then you will get
null with 100% of sure". For cases like: (int) 'string', (int) '123string'
and (int) 'string123' what you got? (It is already supported by PHP):
Answer: int (0), int (123) and int (0), respectively.



Em dom, 21 de abr de 2019 às 06:19, Guilliam Xavier <
guilliam.xav...@gmail.com> escreveu:

> On Sat, Apr 6, 2019 at 9:52 AM Guilliam Xavier
>  wrote:
> >
> > Hello internals,
> >
> > David and I would like to open the discussion on our joint RFC:
> >
> > https://wiki.php.net/rfc/nullable-casting
> >
> > Mainly, it would enable to use e.g. `(?int)$x` besides `(int)$x`.
> >
> > We are looking forward to your feedback [...]
> >
> > Thank you,
>
> Hello again internals,
>
> Thanks everyone for your valuable feedback. I have updated the RFC
> with a new Discussion section to [try to] summarize the various
> arguments raised in this thread.
>
> --
> Guilliam Xavier
>


-- 
David Rodrigues


[PHP-DEV] Re: [RFC] Nullable Casting

2019-04-21 Thread Guilliam Xavier
On Sat, Apr 6, 2019 at 9:52 AM Guilliam Xavier
 wrote:
>
> Hello internals,
>
> David and I would like to open the discussion on our joint RFC:
>
> https://wiki.php.net/rfc/nullable-casting
>
> Mainly, it would enable to use e.g. `(?int)$x` besides `(int)$x`.
>
> We are looking forward to your feedback [...]
>
> Thank you,

Hello again internals,

Thanks everyone for your valuable feedback. I have updated the RFC
with a new Discussion section to [try to] summarize the various
arguments raised in this thread.

-- 
Guilliam Xavier

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php