On Fri, Mar 22, 2024 at 8:02 PM Rowan Tommins [IMSoP]
wrote:
>
> On Fri, 22 Mar 2024, at 17:38, Claude Pache wrote:
>
>
> Le 22 mars 2024 à 16:18, Rowan Tommins [IMSoP] a écrit
> :
>
> $optionalExpiryDateTime = $expiry as ?DateTimeInterface else
> some_other_function($expiry);
> assert($optiona
On Fri, Mar 22, 2024 at 5:51 PM Rowan Tommins [IMSoP]
wrote:
>
> On Fri, 22 Mar 2024, at 12:58, Robert Landers wrote:
> >
> >> $optionalExpiryDateTime = $expiry as ?DateTimeInterface else new
> >> DateTimeImmutable($expiry);
> > I'm not sure I can grok what this does...
> >
> > $optionalExpiryDat
On Fri, 22 Mar 2024, at 17:38, Claude Pache wrote:
>
>> Le 22 mars 2024 à 16:18, Rowan Tommins [IMSoP] a
>> écrit :
>>
>> $optionalExpiryDateTime = $expiry as ?DateTimeInterface else
>> some_other_function($expiry);
>> assert($optionalExpiryDateTime is ?DateTimeInterface); // cannot fail,
>>
> Le 22 mars 2024 à 16:18, Rowan Tommins [IMSoP] a écrit
> :
>
> $optionalExpiryDateTime = $expiry as ?DateTimeInterface else
> some_other_function($expiry);
> assert($optionalExpiryDateTime is ?DateTimeInterface); // cannot fail,
> already asserted by the "as"
I think that the `is` operator
On Fri, 22 Mar 2024, at 12:58, Robert Landers wrote:
>
>> $optionalExpiryDateTime = $expiry as ?DateTimeInterface else new
>> DateTimeImmutable($expiry);
> I'm not sure I can grok what this does...
>
> $optionalExpiryDateTime = ($expiry === null || $expiry instanceof
> DateTimeInterface) ? $expir
On 2024-03-22 10:46, Rowan Tommins [IMSoP] wrote:
On Fri, 22 Mar 2024, at 08:17, Jordi Boggiano wrote:
We perhaps could make sure that as does not throw if used with `??`,
or that `??` catches the type error and returns the right-hand
expression instead:
So to do a nullable typecast you would
On Fri, Mar 22, 2024 at 12:01 PM Rowan Tommins [IMSoP]
wrote:
>
> On Fri, 22 Mar 2024, at 08:17, Jordi Boggiano wrote:
>
> We perhaps could make sure that as does not throw if used with `??`, or that
> `??` catches the type error and returns the right-hand expression instead:
>
> So to do a nulla
On Fri, 22 Mar 2024, at 10:05, Robert Landers wrote:
> After asking an AI for some examples and usages, the most compatible
> one would be C#'s. In actuality, I think it could be hugely simplified
> if we simply return null instead of throwing. There'd be no special
> case for |null, and it would m
On Fri, Mar 22, 2024 at 10:31 AM Jordi Boggiano wrote:
>
> On 2024-03-21 16:02, Robert Landers wrote:
>
> $a as int|float
>
> would be an int, float, or thrown exception.
>
> $a as int|float|null
>
> would be an int, float, or null.
>
> Just a suggestion here which might be more palatable to Rowan
On Fri, 22 Mar 2024, at 08:17, Jordi Boggiano wrote:
> We perhaps could make sure that as does not throw if used with `??`, or that
> `??` catches the type error and returns the right-hand expression instead:
> So to do a nullable typecast you would do:
>
> $a as int|float ?? null
>
While t
On 2024-03-21 16:02, Robert Landers wrote:
$a as int|float
would be an int, float, or thrown exception.
$a as int|float|null
would be an int, float, or null.
Just a suggestion here which might be more palatable to Rowan's wish for
consistency (which I can totally relate to):
We perhaps co
On 22 March 2024 00:04:27 GMT, Robert Landers wrote:
>I think that is where we are getting confused: `null` is a value (or
>at least, the absence of a value). The fact that the type system
>allows it to be used as though its a type (along with true and false)
>is interesting, but I think it is
On Thu, Mar 21, 2024 at 11:06 PM Rowan Tommins [IMSoP]
wrote:
>
> On 21/03/2024 19:03, Robert Landers wrote:
>
> I suppose we are taking this from different viewpoints, yours appears
> to be more of a philosophical one, whereas mine is more of a practical
> one.
>
>
> My main concern is consistenc
>
> What's the advantage of a language construct over the following?
>
> ```php
> /**
> * @template T of object
> * @psalm-assert T $value
> * @param class-string $type
> */
> function as(mixed $value, string $type): mixed
> {
> if (! $value instanceof $type) { throw
> SomeKindOfException::
On 21/03/2024 19:03, Robert Landers wrote:
I suppose we are taking this from different viewpoints, yours appears
to be more of a philosophical one, whereas mine is more of a practical
one.
My main concern is consistency; which is partly philosophical, but does
have practical impact - the same
On Thu, Mar 21, 2024 at 7:01 PM Rowan Tommins [IMSoP]
wrote:
>
> On 21/03/2024 15:02, Robert Landers wrote:
>
> I don't think you are getting what I am saying.
>
> $a as int|float
>
> would be an int, float, or thrown exception.
>
> $a as int|float|null
>
> would be an int, float, or null.
>
>
> I
On 21/03/2024 15:02, Robert Landers wrote:
I don't think you are getting what I am saying.
$a as int|float
would be an int, float, or thrown exception.
$a as int|float|null
would be an int, float, or null.
I get what you're saying, but I disagree that it's a good idea.
If $a is 'hello', b
On Thu, Mar 21, 2024, at 3:02 PM, Robert Landers wrote:
> I don't think you are getting what I am saying.
>
> $a as int|float
>
> would be an int, float, or thrown exception.
>
> $a as int|float|null
>
> would be an int, float, or null.
>
> Robert Landers
> Software Engineer
> Utrecht NL
Hi Rob.
On Thu, Mar 21, 2024 at 12:45 PM Rowan Tommins [IMSoP]
wrote:
>
> On 20/03/2024 23:05, Robert Landers wrote:
>
> In other
> words, I can't think of a case where you'd actually want a Type|null
> and you wouldn't have to check for null anyway.
>
>
> It's not about having to check for null; it's abo
On Thu, Mar 21, 2024 at 12:45 PM Rowan Tommins [IMSoP]
wrote:
>
> On 20/03/2024 23:05, Robert Landers wrote:
>
> In other
> words, I can't think of a case where you'd actually want a Type|null
> and you wouldn't have to check for null anyway.
>
>
> It's not about having to check for null; it's abo
On 20/03/2024 23:05, Robert Landers wrote:
> In other
> words, I can't think of a case where you'd actually want a Type|null
> and you wouldn't have to check for null anyway.
It's not about having to check for null; it's about being able to distinguish
between "a null value, which was one of the
On Wed, Mar 20, 2024 at 8:30 PM Rowan Tommins [IMSoP]
wrote:
>
>
>
> On 20 March 2024 12:51:15 GMT, Robert Landers
> wrote:
>
> >Oh and there isn't any difference between:
> >
> >$x as ?Type
> >
> >or
> >
> >$x as Type|null
>
>
> I'm not sure if I've misunderstood your example, or you've misunde
On 20 March 2024 12:51:15 GMT, Robert Landers wrote:
>Oh and there isn't any difference between:
>
>$x as ?Type
>
>or
>
>$x as Type|null
I'm not sure if I've misunderstood your example, or you've misunderstood mine.
I'm saying that this should be an error, because the value is neither an
in
On Wed, Mar 20, 2024 at 1:47 PM Robert Landers wrote:
>
> On Tue, Mar 19, 2024 at 10:06 PM Rowan Tommins [IMSoP]
> wrote:
> >
> > On 19/03/2024 16:24, Robert Landers wrote:
> >
> > $x = $attributeReflection->newInstance() as ?MyAttribute;
> > if ($x === null) // do something since the attribute i
On Tue, Mar 19, 2024 at 10:06 PM Rowan Tommins [IMSoP]
wrote:
>
> On 19/03/2024 16:24, Robert Landers wrote:
>
> $x = $attributeReflection->newInstance() as ?MyAttribute;
> if ($x === null) // do something since the attribute isn't MyAttribute
>
>
> I think reusing nullability for this would be a
Hi Rowan
On Tue, Mar 19, 2024 at 8:39 PM Rowan Tommins [IMSoP]
wrote:
>
> As well pattern matching, which Ilija mentioned, another adjacent feature is
> a richer set of casting operators. Currently, we can assert that something is
> an int; or we can force it to be an int; but we can't easily s
On 19/03/2024 16:24, Robert Landers wrote:
$x = $attributeReflection->newInstance() as ?MyAttribute;
if ($x === null) // do something since the attribute isn't MyAttribute
I think reusing nullability for this would be a mistake - ideally, the
right-hand side should allow any type, so "$foo as
Hi Marco
On Tue, Mar 19, 2024 at 7:04 PM Marco Aurélio Deleu wrote:
>
> > On 19 Mar 2024, at 14:51, Ilija Tovilo wrote:
> >
> > Hi Robert
> >
> >> On Tue, Mar 19, 2024 at 5:24 PM Robert Landers
> >> wrote:
> >>
> > See https://wiki.php.net/rfc/pattern-matching#throwing_alternative. I
> > beli
Marco Deleu
> On 19 Mar 2024, at 14:51, Ilija Tovilo wrote:
>
> Hi Robert
>
>> On Tue, Mar 19, 2024 at 5:24 PM Robert Landers
>> wrote:
>>
>> I've been thinking about this as an RFC for awhile, but with generics
>> being far off (if at all), I'd like to propose a useful idea: reusing
>>
On Tue, 19 Mar 2024 at 17:46, Deleu wrote:
> On Tue, Mar 19, 2024 at 1:42 PM Marco Pivetta wrote:
>
>> One note: if what you are going for is what `azjezz/psl`, be aware that
>> exception / error tracing design needs special attention here: it's not as
>> simple as it looks!
>>
>
> I believe you
Hi Robert
On Tue, Mar 19, 2024 at 5:24 PM Robert Landers wrote:
>
> I've been thinking about this as an RFC for awhile, but with generics
> being far off (if at all), I'd like to propose a useful idea: reusing
> the AS keyword in a different context.
>
> Example:
>
> $x = $attributeReflection->ne
On Tue, Mar 19, 2024 at 1:42 PM Marco Pivetta wrote:
> One note: if what you are going for is what `azjezz/psl`, be aware that
> exception / error tracing design needs special attention here: it's not as
> simple as it looks!
>
I believe you answered your own question here. The proposal seems fa
Hey Robert,
On Tue, 19 Mar 2024 at 17:24, Robert Landers
wrote:
> Hello internals,
>
> I've been thinking about this as an RFC for awhile, but with generics
> being far off (if at all), I'd like to propose a useful idea: reusing
> the AS keyword in a different context.
>
> Example:
>
> $x = $at
Hello internals,
I've been thinking about this as an RFC for awhile, but with generics
being far off (if at all), I'd like to propose a useful idea: reusing
the AS keyword in a different context.
Example:
$x = $attributeReflection->newInstance() as MyAttribute;
This would essentially perform th
34 matches
Mail list logo