Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Marcos Passos
It is just a (draft) proposal. Anyway, the RFC does not force you to
declare a mixed type but brings an option for who wants to.

On Fri, Feb 8, 2019 at 13:03 Robert Korulczyk  wrote:

> There is no reason to introduce `mixed` type-hint if it does not provide
> any validation and works the same as no type-hint at all.
>
> Regards,
> Robert Korulczyk
>
> W dniu 08.02.2019 o 15:54, Marcos Passos pisze:
> > Those cases should be handled with runtime validation, there is no
> reason for changing the concept of mixed.
> >
> > On Fri, Feb 8, 2019 at 12:39 Robert Korulczyk  > wrote:
> >
> > > Could you clarify on a use-case for changing the semantics of
> `mixed`?
> >
> > For example storage which does not allow to store null. Like simple
> cache which treats null as "miss", so it is not able to cache null as value.
> >
> > Obviously it is not a deal breaker and use case is quite rare
> anyway, but this is just example when mixed type-hint may work as actual
> type-hint, not
> > just replacement for PHPDoc or equivalent of... nothing.
> >
> >
> >
> > Regards,
> > Robert Korulczyk
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>


Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Robert Korulczyk
> Could you clarify on a use-case for changing the semantics of `mixed`?

For example storage which does not allow to store null. Like simple cache which 
treats null as "miss", so it is not able to cache null as value.

Obviously it is not a deal breaker and use case is quite rare anyway, but this 
is just example when mixed type-hint may work as actual type-hint, not
just replacement for PHPDoc or equivalent of... nothing.



Regards,
Robert Korulczyk

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



Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Dan Ackroyd
On Fri, 8 Feb 2019 at 07:20, Rasmus Schultz  wrote:
>
> Regarding the mixed type-hint RFC:
>
> https://wiki.php.net/rfc/mixed-typehint

The status of the RFC is in "In Draft" and you don't appear to be the
author of the RFC.

It is not appropriate for someone other than the author to start the
discussion of an RFC.

Please can everyone wait until the author of the the RFC has finished
writing it, before saying that it's wrong?

cheers
Dan

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



Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Girgias
On Fri, 8 Feb 2019 at 13:13, Robert Korulczyk  wrote:

> Sounds like an arbitrary interpretation. Treating `?mixed" as "top type"
> (including null) would be more practical and consistent with other
> type-hints.
>
> Regards,
> Robert Korulczyk
>

The whole PHP Documentation is based around the fact that `mixed` includes
`null`, would it make more "sense" that `null` is not included, probably,
also even if I do like the proposal it seems this is just to add a
type-hint so you can *mostly* type hint all function.
But in this regards I would prefer that the scalar RFC type hint goes back
into discussion as it has potentially more use case IMHO.

Best regards

George P. Banyard


Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Marco Pivetta
On Fri, 8 Feb 2019, 13:13 Robert Korulczyk  Sounds like an arbitrary interpretation. Treating `?mixed" as "top type"
> (including null) would be more practical and consistent with other
> type-hints.
>

The PHP ecosystem (libraries) already uses `mixed` as a type including
`null`. You can survey for usages of `mixed|null`, which is currently
normalised to `mixed` by existing static analysis tooling (psalm, phpstan).

Even then, by adding a non-nullable almost-top-type doesn't seem helpful:
"here's something random, just make sure it isn't null". That's something
more interesting for an eventual union type RFC (revival?).

Could you clarify on a use-case for changing the semantics of `mixed`?

>


Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Robert Korulczyk
Sounds like an arbitrary interpretation. Treating `?mixed" as "top type" 
(including null) would be more practical and consistent with other type-hints.

Regards,
Robert Korulczyk

W dniu 08.02.2019 o 12:47, Marco Pivetta pisze:
> `mixed` is the "top" type, which means that it contains anything at all. See 
> https://en.wikipedia.org/wiki/Top_type
> 
> On Fri, 8 Feb 2019, 12:45 Robert Korulczyk   wrote:
> 
> What definition?
> 
> Regards,
> Robert Korulczyk
> 
> W dniu 08.02.2019 o 12:37, Marco Pivetta pisze:
> > Mixed includes null by definition.
> >
> > On Fri, 8 Feb 2019, 12:21 Robert Korulczyk    > wrote:
> >
> >     > Without this, the mixed type-hint is basically meaningless noise, 
> is it
> >     > not? About as effective is a doc-block?
> >
> >     This mixed type seems to be meaningless by design since its main 
> goal is to work the same as if it was no type-hint at all...
> >
> >     Another thing is that including null as part of mixed is not very 
> pragmatic - mixed could be used to disallow null, so it will actually work
> for type
> >     check.
> >
> >
> >
> >     Regards,
> >     Robert Korulczyk
> >
> >     --
> >     PHP Internals - PHP Runtime Development Mailing List
> >     To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 

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



Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Marco Pivetta
`mixed` is the "top" type, which means that it contains anything at all.
See https://en.wikipedia.org/wiki/Top_type

On Fri, 8 Feb 2019, 12:45 Robert Korulczyk  What definition?
>
> Regards,
> Robert Korulczyk
>
> W dniu 08.02.2019 o 12:37, Marco Pivetta pisze:
> > Mixed includes null by definition.
> >
> > On Fri, 8 Feb 2019, 12:21 Robert Korulczyk  rob...@korulczyk.pl> wrote:
> >
> > > Without this, the mixed type-hint is basically meaningless noise,
> is it
> > > not? About as effective is a doc-block?
> >
> > This mixed type seems to be meaningless by design since its main
> goal is to work the same as if it was no type-hint at all...
> >
> > Another thing is that including null as part of mixed is not very
> pragmatic - mixed could be used to disallow null, so it will actually work
> for type
> > check.
> >
> >
> >
> > Regards,
> > Robert Korulczyk
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>


Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Robert Korulczyk
What definition?

Regards,
Robert Korulczyk

W dniu 08.02.2019 o 12:37, Marco Pivetta pisze:
> Mixed includes null by definition.
> 
> On Fri, 8 Feb 2019, 12:21 Robert Korulczyk   wrote:
> 
> > Without this, the mixed type-hint is basically meaningless noise, is it
> > not? About as effective is a doc-block?
> 
> This mixed type seems to be meaningless by design since its main goal is 
> to work the same as if it was no type-hint at all...
> 
> Another thing is that including null as part of mixed is not very 
> pragmatic - mixed could be used to disallow null, so it will actually work 
> for type
> check.
> 
> 
> 
> Regards,
> Robert Korulczyk
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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



Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Marco Pivetta
Mixed includes null by definition.

On Fri, 8 Feb 2019, 12:21 Robert Korulczyk  > Without this, the mixed type-hint is basically meaningless noise, is it
> > not? About as effective is a doc-block?
>
> This mixed type seems to be meaningless by design since its main goal is
> to work the same as if it was no type-hint at all...
>
> Another thing is that including null as part of mixed is not very
> pragmatic - mixed could be used to disallow null, so it will actually work
> for type
> check.
>
>
>
> Regards,
> Robert Korulczyk
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP-DEV] Mixed type-hint

2019-02-08 Thread Robert Korulczyk
> Without this, the mixed type-hint is basically meaningless noise, is it
> not? About as effective is a doc-block?

This mixed type seems to be meaningless by design since its main goal is to 
work the same as if it was no type-hint at all...

Another thing is that including null as part of mixed is not very pragmatic - 
mixed could be used to disallow null, so it will actually work for type
check.



Regards,
Robert Korulczyk

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



[PHP-DEV] Mixed type-hint

2019-02-07 Thread Rasmus Schultz
Regarding the mixed type-hint RFC:

https://wiki.php.net/rfc/mixed-typehint

> When no native type is present, it is unclear what type is expected

Regarding variance - in the examples shown in the RFC, it is still unclear
whether your intention was variance, or if you just omitted the type-hint
by accident.

The introduction of the mixed type-hint, as I was trying to explain
earlier, could have addressed that problem - by allowing mixed variance
only with an explicit type-hint and disallowing implicit variance.

As I pointed out when the variance RFCs were accepted, it's too late to
remove this allowance now, as that would be a breaking change.

However, could we at least make it an E_STRICT?

So that, given the following:

class A {
public function foo(int $value) {}
}

The following would emit an E_STRICT:

class B extends A {
public function foo($value) {} // E_STRICT: implied variance
}

And the following would not:

class B extends A {
public function foo(mixed $value) {} // explicit variance
}

An E_STRICT is not a breaking change, right?

At least then we can map E_STRICT to an ErrorException during development.

Without this, the mixed type-hint is basically meaningless noise, is it
not? About as effective is a doc-block?