On 11/04/2019 08:52, Guilliam Xavier wrote:
Honestly as a newbie here I'm feeling more tired than I had expected
and I'm not sure if we'll find a syntax+semantics pair that will reach
a consensus... Suggestions and comments very welcome!
Don't stress yourself about it. At the end of the day we'
OK, I'll try to sum up a bit the recent messages (since Nikita's one):
Mark Randall wrote:
> As is implied from the name, an implicit cast is done because the code
> needs it to, not because it has been told to by the caller. It is
> natural to be more conservative when doing something that has no
On 10/04/2019 22:30, Benjamin Morel wrote:
Your arguments are perfectly valid and make sense, I guess this is a matter
of not viewing different semantics for explicit and implicit cast as
inconsistencies.
It's an interesting discussion and I appreciate you engaging on it.
I wonder, perhaps, if
> That's exactly what it is, and thanks to null coalescence, you then have
> an easy available ability to either check if it succeeded, or default to
> another value.
Your arguments are perfectly valid and make sense, I guess this is a matter
of not viewing different semantics for explicit and imp
On 10/04/2019 18:34, Benjamin Morel wrote:
So why would you have different semantics for implicit `(?int)` cast vs `:
?int` function return type cast, if they're both *out*?
Return type cast has the same semantics as parameter type cast.
I would have to disagree with this as I think of "return"
> Function arguments specify what goes *in* to a function, whereas casts
> and return types specify what comes *out* of the function.
So why would you have different semantics for implicit `(?int)` cast vs `:
?int` function return type cast, if they're both *out*?
Return type cast has the same sem
On 10/04/2019 17:15, Benjamin Morel wrote:
No offense, but how can casting semantics different from those already used
in implicit casting be intuitive?
As is implied from the name, an implicit cast is done because the code
needs it to, not because it has been told to by the caller. It is
nat
>
> I believe returning null in those situations makes the most intuative
> sense, yes.
No offense, but how can casting semantics different from those already used
in implicit casting be intuitive?
function a(int $x) { var_export($x); }
function b(?int $x) { var_export($x); }
a("12
On 10/04/2019 16:16, Guilliam Xavier wrote:
var_dump((?int) $obj); // would you want it to print `NULL`?
var_dump((?string) $obj); // would you want it to print `NULL`?
I believe returning null in those situations makes the most intuative
sense, yes.
> var_dump((int) $obj); // Notice, then p
On Wed, Apr 10, 2019 at 4:34 PM Mark Randall wrote:
>
> (Continuing from my previous post in a different thread...)
>
> IMHO a cast such as ([?]type) would be better described as passing a
> mixed value through a function which has a return type of whatever is in
> the cast... the mechanics of tha
On Wed, Apr 10, 2019 at 12:52 PM Nikita Popov wrote:
>
> I'm a bit concerned that there are two possible semantics for what (?int)
> does:
>
> 1. What I would intuitively expect: A fallible integer cast. I.e. try to
> cast to integer and if not possible return null. So (?int) "foobar" becomes
> n
On 10/04/2019 13:03, Benjamin Morel wrote:
There is only one, if we align the semantics of explicit and implicit
casting: you wouldn't expect this:
function test(?int $bar) { var_export($bar); }
test("abc");
...to output 'null'?
(Continuing from my previous post in a different threa
>
> I'm a bit concerned that there are two possible semantics for what (?int)
> does:
There is only one, if we align the semantics of explicit and implicit
casting: you wouldn't expect this:
function test(?int $bar) { var_export($bar); }
test("abc");
...to output 'null'?
--
Ben
On Sat, Apr 6, 2019 at 9:53 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 feedb
On 09/04/2019 08:32, Guilliam Xavier wrote:
I do kind of like the idea in the RFC, but I think it needs a better
argument for it.
For your other points, I find that Claude Pache has given pretty good
arguments in the meantime (thanks!) =) (By the way, I also thought
about say, "nullable_intval()
Dan Ackroyd wrote:
>
> I'm guessing you don't actually have ths function getIntOrNull() in
> your code-base? To help me understand where this would be useful,
> could you provide some 'real-world' code where this would be useful?
Hello, thanks for digging in :)
Here's a "real-world" situation I
On Mon, Apr 8, 2019 at 11:55 PM M. W. Moe wrote:
>
> [redacted]
>
> On Mon, Apr 8, 2019 at 7:44 AM Dan Ackroyd wrote:
>
> > On Mon, 8 Apr 2019 at 04:21, M. W. Moe wrote:
> > >
> > > [redacted]
> >
> > [redacted]
> >
As the initiator of this thread (who hasn't had the time to answer
questions ye
Hello,
i) was intentional.
ii) Not our fault, we do not have this function in our code-base and won't
ever; we would not even dare 8).
Cheers!
On Mon, Apr 8, 2019 at 7:44 AM Dan Ackroyd wrote:
> On Mon, 8 Apr 2019 at 04:21, M. W. Moe wrote:
> >
> > Hello,
> >
> > looks like you are living in
On Mon, Apr 8, 2019 at 6:05 AM David Rodrigues
wrote:
> Current solution:
>
> $itemsPerPage = Input::get('itemsPerPage') ?: null;
> $itemsPerPage = $itemsPerPage !== null ? (int) $itemsPerPage : null;
>
> $paginator->setItemsPerPage($itemsPerPage); // OK
>
> With this new feature: just...
>
> $pa
> Le 8 avr. 2019 à 07:05, David Rodrigues a écrit :
>
> And about "settype($variable, "?int")" it was requested on original mailing
> by Claude Pache.
PHP has several ways to perform casting:
1. (int) $foo
2. settype($foo, 'int');
3. intval($foo)
They are occasions where the programmer will p
> Le 8 avr. 2019 à 12:24, Stephen Reay a écrit :
>
> if your target ’type’ is `?int` and you pass an empty string, wouldn’t you
> expect to get `null` rather than `0` ?
You should get the same value than you get in:
```php
declare(strict_types=0);
function foo(?int $x) {
return $x;
}
On Mon, 8 Apr 2019 at 06:05, David Rodrigues wrote:
>
> Question: why just not check if $itemsPerPage is set like:
> ...
> Answer: because in this example we could do that (although the new solution
> is much more practical).
Well, I disagree on that. That code is perfectly fine to me, and
havin
On Mon, 8 Apr 2019 at 04:21, M. W. Moe wrote:
>
> Hello,
>
> looks like you are living in a pig stall; php would be benefit from type
> safety when explicitly required.
>
> Regards.
Hi Moe,
It seems you:
i) accidentally hit reply, instead of reply all. This is an easy
mistake to make.
ii) App
> if your target ’type’ is `?int` and you pass an empty string, wouldn’t
you expect to get `null` rather than `0` ?
I'd personally expect an `Error`, but this is not very much in line with
current casting semantics.
You have a point here, there is no clear answer for this edge case.
Maybe befor
> On 8 Apr 2019, at 16:35, Benjamin Morel wrote:
>
>> register_cast_function('?int', 'castToIntOrNull');
>
> I would quite oppose such a generic implementation, as it might have
> unexpected consequences in other parts of the codebase : it's a global
> configuration set at runtime.
>
> I quit
> register_cast_function('?int', 'castToIntOrNull');
I would quite oppose such a generic implementation, as it might have
unexpected consequences in other parts of the codebase : it's a global
configuration set at runtime.
I quite like the idea of nullable casting though, as I've come across a fe
Real world example:
class Paginator {
// If null, will use the default value (eg. 15), else, it will requires
an int.
public function setItemsPerPage(?int $itemsPerPage) { ... }
}
// Info that came from user input.
// It will be a string, and not a integer, like we need.
$itemsPerPage = I
On Sat, 6 Apr 2019 at 08:53, 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`.
>
I'm guessing you don't actually have t
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 and, if possible, help to fill
in the "RFC Impact" subsections (ho
29 matches
Mail list logo