Dear Internals,
I would like to discuss a small RFC for reserving more types in PHP 7:
https://wiki.php.net/rfc/reserve_more_types_in_php_7
Essentially it proposes to reserve:
Sorry: Apparently hit some hotkey for send.
Dear Internals,
I would like to discuss a small RFC for reserving more types in PHP 7:
https://wiki.php.net/rfc/reserve_more_types_in_php_7Essentially it proposes to reserve:
int, integer
bool, boolean
true, false
float, double
string
null
It does not make them keywords; it only prevents them from being used
in class, interface, trait and namespace names.
Hi Levi,
Just my opinion :
Add 'resource', 'object', 'scalar', 'mixed', 'numeric'
Remove 'double' (avoid this alias if we decide to encourage 'float' everywhere)
Not sure we'll use Boolean and integer but reserve also.
Hope 'null', 'true', and 'false' can technically be used as type hints. If not, bad news, especially for null. Love 'int|false' as return type !
Regards
François
-----Message d'origine-----
De : morrison.levi@gmail.com [mailto:morrison.levi@gmail.com] De la part
de Levi Morrison
Envoyé : vendredi 20 février 2015 02:36
À : internals
Objet : [PHP-DEV] Re: [RFC] Reserving More Types in PHP 7Sorry: Apparently hit some hotkey for send.
Dear Internals,
I would like to discuss a small RFC for reserving more types in PHP 7:
https://wiki.php.net/rfc/reserve_more_types_in_php_7Essentially it proposes to reserve:
int, integer
bool, boolean
true, false
float, double
string
nullIt does not make them keywords; it only prevents them from being used
in class, interface, trait and namespace names.
Hi,
Hi Levi,
Just my opinion :
Add 'resource', 'object', 'scalar', 'mixed', 'numeric'
Remove 'double' (avoid this alias if we decide to encourage 'float' everywhere)
Not sure we'll use Boolean and integer but reserve also.
Hope 'null', 'true', and 'false' can technically be used as type hints. If not, bad news, especially for null. Love 'int|false' as return type !
I'd rather not reserve 'resource'. Such a hint may be useful in the
short term, but there already are plans to turn the current resources
into objects, and with the rise of REST lately it is also an obvious
base class/interface/trait name.
Agree on 'double' though ... if we want to discourage its usage, we
might even think of deprecating it.
Cheers,
Andrey.
Add 'resource', 'object', 'scalar', 'mixed', 'numeric'
If someone wants to reserve these I will leave them up to another RFC,
as I suspect they are more controversial than what I have proposed.
Remove 'double' (avoid this alias if we decide to encourage 'float' everywhere)
Not sure we'll use Boolean and integer but reserve also.
Hope 'null', 'true', and 'false' can technically be used as type hints. If not, bad news, especially for null. Love 'int|false' as return type !
This is out of scope for this RFC, but if this RFC passes they would
be reserved which means this could be done without BC breaks in the
future.
I'd rather not reserve 'resource'. Such a hint may be useful in the
short term, but there already are plans to turn the current resources
into objects, and with the rise of REST lately it is also an obvious
base class/interface/trait name.Agree on 'double' though ... if we want to discourage its usage, we
might even think of deprecating it.
While deprecating it might be a good course of action, it is out of
scope of this RFC. I personally think that reserving it is a good way
to discourage its use: simply reserve it and then don't use it for
anything. If we decide not to use the aliases if we have scalar types
and the aliases are reserved this would prevent users from making
custom types from the aliases. In my opinion this a Good Thing.
Hi,
Agree on 'double' though ... if we want to discourage its usage, we
might even think of deprecating it.While deprecating it might be a good course of action, it is out of
scope of this RFC. I personally think that reserving it is a good way
to discourage its use: simply reserve it and then don't use it for
anything. If we decide not to use the aliases if we have scalar types
and the aliases are reserved this would prevent users from making
custom types from the aliases. In my opinion this a Good Thing.
Well, I meant to deprecate is_double()
, is_real()
and the
corresponding explicit casts. I might be missing other places when
they are used, not sure, but the point would be to stop using these
names for scalar types at all, so that everybody can freely use them
for class/trait/interface names ... I don't think anybody would do
that only for pseudo-scalar hinting objects.
So, while yes - that's outside of this RFC's scope, reserving them as
keywords would be the opposite of what I had in mind.
Cheers,
Andrey.
Hi,
First of all I'd like to see this (clean) RFC formalized / ratified
sooner rather than later.
Just to chime in here from a user / framework developer perspective in
regards to double / real / boolean / integer reservation: i'd
like to see these aliases (and the is_*-functions etc) be deprecated /
removed sooner than later instead of kept around. It's minor, i know,
but consistency wins above a quick find/replace above all. With lesser
roads to the destination (rome), the easier the route to follow ;)
Atleast have it on a roadmap somewhere instead of keeping it around
and in every discussion with regards to reserved keywords, typehints,
return types etc etc
Thanks and keep up the good work ! (can't wait to see what PHP7.0 will
actually bring to the table)
Thnx,
Robin Speekenbrink
2015-02-20 17:11 GMT+01:00 Andrey Andreev narf@devilix.net:
Hi,
Agree on 'double' though ... if we want to discourage its usage, we
might even think of deprecating it.While deprecating it might be a good course of action, it is out of
scope of this RFC. I personally think that reserving it is a good way
to discourage its use: simply reserve it and then don't use it for
anything. If we decide not to use the aliases if we have scalar types
and the aliases are reserved this would prevent users from making
custom types from the aliases. In my opinion this a Good Thing.Well, I meant to deprecate
is_double()
,is_real()
and the
corresponding explicit casts. I might be missing other places when
they are used, not sure, but the point would be to stop using these
names for scalar types at all, so that everybody can freely use them
for class/trait/interface names ... I don't think anybody would do
that only for pseudo-scalar hinting objects.So, while yes - that's outside of this RFC's scope, reserving them as
keywords would be the opposite of what I had in mind.Cheers,
Andrey.
Hi,
On Fri, Feb 20, 2015 at 4:21 AM, Andrey Andreev narf@devilix.net
wrote:Agree on 'double' though ... if we want to discourage its usage, we
might even think of deprecating it.While deprecating it might be a good course of action, it is out of
scope of this RFC. I personally think that reserving it is a good way
to discourage its use: simply reserve it and then don't use it for
anything. If we decide not to use the aliases if we have scalar types
and the aliases are reserved this would prevent users from making
custom types from the aliases. In my opinion this a Good Thing.Well, I meant to deprecate
is_double()
,is_real()
and the
corresponding explicit casts. I might be missing other places when
they are used, not sure, but the point would be to stop using these
names for scalar types at all, so that everybody can freely use them
for class/trait/interface names ... I don't think anybody would do
that only for pseudo-scalar hinting objects.So, while yes - that's outside of this RFC's scope, reserving them as
keywords would be the opposite of what I had in mind.
Right, but it is a yes/no list of options.
It makes no sense to have competitive RFCs for such a trivial set of
choices.
Cheers,
Andrey.
Add 'resource', 'object', 'scalar', 'mixed', 'numeric'
If someone wants to reserve these I will leave them up to another RFC,
as I suspect they are more controversial than what I have proposed.
Done https://wiki.php.net/rfc/reserve_even_more_types_in_php_7
-Sara
Hi Andrey,
I think the question of reserving 'resource' or not is not the main one.
The question of having to reserve keywords is much more fundamental and needs to be addressed first. I expect it to be clear for everyone that, as long as we share the same naming space between class/interface/trait names and type hinting keywords, each addition of a new keyword will be a real problem. So, we may reserve keywords in advance but it cannot be more than a workaround. If we don't address the issue now, we'll end up with weird names for type hints, just because appropriate ones are too appropriate and potentially taken for existing or future classes, without any way to evaluate the potential BC break, let alone the potential introduction of a third naming space with a future 'typedef' feature ;). We see the case today with 'resource' but that's just the beginning. What about 'mixed', 'scalar', or others I don't imagine yet ? The race to reserving keywords is lost in advance.
Another point is that, thinking the reverse way, developers can legitimately ask why they cannot choose 'resource' as a class name, when the reason for this is a design mistake made when the 'array' type hint was introduced, or even before, when class hints were introduced without thinking the mechanism would be necessarily be extended.
Just a detail: I respectfully suggest anyone not to waste time to explain that the problem is solved by using lowercase-only keywords, at least not to me ;)
So, we need to propose a migration path towards a cleaner syntax. The STH RFC we are writing proposes one, keeping it as smooth as possible because the feature is heavily used.
Back to the particular case of 'resource': As the future of resources may be to be converted to objects while keeping the same API, the STH RFC will propose to define the 'resource' type hint as accepting 'IS_RESOURCE|IS_OBJECT', without conversion. Then the user who received it can distinguish with is_resource/is_object() if needed.
So, 'resource' and 'resource|object' will be synonyms, while more precise users can use something like 'resource|object(GMP)'. All of these syntaxes will provide full BC when switching from resource to OO.
Thought ?
Regards
François
Hi,
Hi Andrey,
I think the question of reserving 'resource' or not is not the main one.
The question of having to reserve keywords is much more fundamental and needs to be addressed first. I expect it to be clear for everyone that, as long as we share the same naming space between class/interface/trait names and type hinting keywords, each addition of a new keyword will be a real problem. So, we may reserve keywords in advance but it cannot be more than a workaround. If we don't address the issue now, we'll end up with weird names for type hints, just because appropriate ones are too appropriate and potentially taken for existing or future classes, without any way to evaluate the potential BC break, let alone the potential introduction of a third naming space with a future 'typedef' feature ;). We see the case today with 'resource' but that's just the beginning. What about 'mixed', 'scalar', or others I don't imagine yet ? The race to reserving keywords is lost in advance.
Another point is that, thinking the reverse way, developers can legitimately ask why they cannot choose 'resource' as a class name, when the reason for this is a design mistake made when the 'array' type hint was introduced, or even before, when class hints were introduced without thinking the mechanism would be necessarily be extended.
Just a detail: I respectfully suggest anyone not to waste time to explain that the problem is solved by using lowercase-only keywords, at least not to me ;)
So, we need to propose a migration path towards a cleaner syntax. The STH RFC we are writing proposes one, keeping it as smooth as possible because the feature is heavily used.
Back to the particular case of 'resource': As the future of resources may be to be converted to objects while keeping the same API, the STH RFC will propose to define the 'resource' type hint as accepting 'IS_RESOURCE|IS_OBJECT', without conversion. Then the user who received it can distinguish with is_resource/is_object() if needed.
So, 'resource' and 'resource|object' will be synonyms, while more precise users can use something like 'resource|object(GMP)'. All of these syntaxes will provide full BC when switching from resource to OO.
Thought ?
Sorry François, but I really didn't intend to go further into that topic.
If Levi decides to add it as a second, optional vote - it's his
proposal and that's fine with me. I only expressed my opinon about
your suggestion to also reserve 'resource', because I don't have
voting karma and RFC discussion is my only way of influencing
decisions.
Cheers,
Andrey.
I would like to discuss a small RFC for reserving more types in PHP 7:
https://wiki.php.net/rfc/reserve_more_types_in_php_7Essentially it proposes to reserve:
int, integer
bool, boolean
true, false
float, double
string
null
+1 -- I was planning to put this up today and got waylaid.
Add 'resource', 'object', 'scalar', 'mixed', 'numeric'
Remove 'double' (avoid this alias if we decide to encourage 'float' everywhere)
Hope 'null', 'true', and 'false' can technically be used as type hints.
If not, bad news, especially for null. Love 'int|false' as return type !
If I were to change one thing, it'd be to add some metatypes (possibly as a separate vote):
I also agree with everything François said. Reserve these additional
types (possibly in a separate vote, up to you).
-Sara
2015-02-20 2:36 GMT+01:00 Levi Morrison levim@php.net:
int, integer
bool, boolean
true, false
float, double
I guess we should add 'real' here as well, since we still have the
(real) type cast and is_() type check for consistency:
C:\dev\php-src>php -r "var_dump((real) 42, is_real(13.37));"
float(42)
bool(true)
string
null
--
regards,
Kalle Sommer Nielsen
kalle@php.net
2015-02-20 2:36 GMT+01:00 Levi Morrison levim@php.net:
int, integer
bool, boolean
true, false
float, doubleI guess we should add 'real' here as well, since we still have the
(real) type cast and is_() type check for consistency:C:\dev\php-src>php -r "var_dump((real) 42, is_real(13.37));"
float(42)
bool(true)
How do others else feel about this? I am undecided at the moment.