Announcing this in its own thread:
https://wiki.php.net/rfc/reserve_even_more_types_in_php_7
This RFC acts as an addition to Levi's
https://wiki.php.net/rfc/reserve_more_types_in_php_7 by creating a
forum for voting on additional types not included in his RFC:
resource, object, scalar, mixed, numeric
-Sara
Announcing this in its own thread:
https://wiki.php.net/rfc/reserve_even_more_types_in_php_7This RFC acts as an addition to Levi's
https://wiki.php.net/rfc/reserve_more_types_in_php_7 by creating a
forum for voting on additional types not included in his RFC:
resource, object, scalar, mixed, numeric
Announcing this in its own thread:
https://wiki.php.net/rfc/reserve_even_more_types_in_php_7This RFC acts as an addition to Levi's
https://wiki.php.net/rfc/reserve_more_types_in_php_7 by creating a
forum for voting on additional types not included in his RFC:
resource, object, scalar, mixed, numeric
From the RFC:
“resource”
“object”
“scalar”
“mixed”
“numeric”
"... prohibits their usage as class, interface and trait names."
This is such a major BC break.
- Markus
Am 20.02.2015 um 19:51 schrieb Markus Fischer:
From the RFC:
“resource” “object” “scalar” “mixed” “numeric”
"... prohibits their usage as class, interface and trait names."
This is such a major BC break.
I just wonder why we need to prohibit these names. Can types not reside
in the global \ namespace? We could then change the class resolution
rules to allow to look also in \ as is done for functions currently.
Thanks
Dennis
Hi,
This is not a question of namespace resolution. Built-in type hints and namespaces have nothing in common.
It is just about the logic of :
Class resource {
...
}
Function foo(resource $arg, ...)
Do we check $arg to be I_RESOURCE or an instance of the 'resource' class ?
Hope I'm clear.
-----Message d'origine-----
De : Dennis Birkholz [mailto:dennis@birkholz.biz]
Envoyé : vendredi 20 février 2015 20:17
À : internals@lists.php.net
Objet : Re: [PHP-DEV] [RFC] Reserve EVEN MORE types for PHP7Am 20.02.2015 um 19:51 schrieb Markus Fischer:
From the RFC:
“resource” “object” “scalar” “mixed” “numeric”
"... prohibits their usage as class, interface and trait names."
This is such a major BC break.
I just wonder why we need to prohibit these names. Can types not reside
in the global \ namespace? We could then change the class resolution
rules to allow to look also in \ as is done for functions currently.Thanks
Dennis
Hello
Am 20.02.2015 um 22:03 schrieb François Laupretre:
I just wonder why we need to prohibit these names. Can types not reside
in the global \ namespace? We could then change the class resolution
rules to allow to look also in \ as is done for functions currently.Thanks
DennisThis is not a question of namespace resolution. Built-in type hints and namespaces have nothing in common.
I do not know how the actual implementation works, but I assume there is
a symbol table for each namespace that contains a list of
class/trait/interface names for that namespace. Why not enhance this
mechanism to contain all type information for each namespace? Simple
types go into that symbol table, type aliases, type defs/enum types (if
such a thing gets implemented), union types, etc. In addition, if the
current namespace symbol table does not contain an entry (and the
autoloader fails), the root namespace is tested for a name.
It is just about the logic of :
Class resource {
...
}Function foo(resource $arg, ...)
Do we check $arg to be I_RESOURCE or an instance of the 'resource' class ?
The class definition would give an error, as "resource" already exists
in the topmost namespace.
namespace test {
Class resource { ... }
function foo(resource $arg, ...)
}
function bar(resource $arg, ...)
foo uses the class test\resource, bar uses the resource type from the
root namespace.
Maybe PHP works completely different internally and this is not
feasible. But reserving some names from being valid as a class name
sounds like a hack, I would prefer a clean and generic solution.
Thanks
Dennis
Hi Dennis,
I didn't consider defining builtin type hints as classes because :
- I think it would be slower, and we need speed, but I agree, I did no test
- no pre-defined namespace exists to handle this
- Reverting to the root namespace makes it twice slower. The case of functions is nothing more than a hack to have a flawed design approved by all means.
- Storing builtin types in the root namespace would cause exactly the same problem of sharing a naming space with user-defined names.
- and probably the most important one: the implementation is based upon the ZPP layer, which allows internal and userland type hinting to follow exactly the same logic.
About namespaces : no type hinting feature is currently planned at the namespace level, except the usual class resolution when a class name is used as hint. Some may exist in the future as there will probably be more links between built-in types and classes, such as specializing and combining builtin types using a userland class or exposing builtin-types as classes.
Regards
François
-----Message d'origine-----
De : Dennis Birkholz [mailto:dennis@birkholz.biz]
Envoyé : vendredi 20 février 2015 22:22
À : internals@lists.php.net
Objet : Re: [PHP-DEV] [RFC] Reserve EVEN MORE types for PHP7Hello
Am 20.02.2015 um 22:03 schrieb François Laupretre:
I just wonder why we need to prohibit these names. Can types not reside
in the global \ namespace? We could then change the class resolution
rules to allow to look also in \ as is done for functions currently.Thanks
DennisThis is not a question of namespace resolution. Built-in type hints and
namespaces have nothing in common.I do not know how the actual implementation works, but I assume there is
a symbol table for each namespace that contains a list of
class/trait/interface names for that namespace. Why not enhance this
mechanism to contain all type information for each namespace? Simple
types go into that symbol table, type aliases, type defs/enum types (if
such a thing gets implemented), union types, etc. In addition, if the
current namespace symbol table does not contain an entry (and the
autoloader fails), the root namespace is tested for a name.It is just about the logic of :
Class resource {
...
}Function foo(resource $arg, ...)
Do we check $arg to be I_RESOURCE or an instance of the 'resource' class ?
The class definition would give an error, as "resource" already exists
in the topmost namespace.namespace test {
Class resource { ... }
function foo(resource $arg, ...)
}function bar(resource $arg, ...)
foo uses the class test\resource, bar uses the resource type from the
root namespace.Maybe PHP works completely different internally and this is not
feasible. But reserving some names from being valid as a class name
sounds like a hack, I would prefer a clean and generic solution.Thanks
Dennis
Hi François,
Am 21.02.2015 um 03:03 schrieb François Laupretre:
I didn't consider defining builtin type hints as classes because :
I was not proposing using internal types as classes. I just want to
define a clean behavior for all kinds of types that may exist some time
in PHP. As no scalar type hints RFC has passed so far, we could also
define it in a clean way and just put the scalar types into , then we
can not have the conflicting classes there and have to use "function
foo(\int $c)" instead of "function foo(int $c)" which is a lot better
that switching type hints for classes to something like "function bar
(object(my\namespaced\class) $a)".
- I think it would be slower, and we need speed, but I agree, I did no test
I don't know this.
- no pre-defined namespace exists to handle this
There is \
- Reverting to the root namespace makes it twice slower. The case of functions is nothing more than a hack to have a flawed design approved by all means.
Also you could just "use \int, \string;" on top of the file, than
"function foo(int $c)" is ok. In total, I think that is the BC-break
safe way to go, it will keep the door wide open for union types, etc.
without the worry of BC breaks. We could leave out all the hacky stuff
here. We could even use \PHP as the namespace to go.
- Storing builtin types in the root namespace would cause exactly the same problem of sharing a naming space with user-defined names.
No, because you can just move you classes into a namespace and add some
use statements to the top of the consumer files (with different
namespaces in use). With the current proposals, you have to invent new
names for you classes.
- and probably the most important one: the implementation is based upon the ZPP layer, which allows internal and userland type hinting to follow exactly the same logic.
I consider this a detail that should not prevent a clean language
design. It may mean more work in the short time but I think this will
greatly increase the adoption rate if we can eliminate the BC break here.
About namespaces : no type hinting feature is currently planned at the namespace level, except the usual class resolution when a class name is used as hint. Some may exist in the future as there will probably be more links between built-in types and classes, such as specializing and combining builtin types using a userland class or exposing builtin-types as classes.
Thanks
Dennis
Hi Dennis,
Please give more precise examples. I'm afraid I don't understand :
If you use \ as prefix for builtin types, how do you distinguish this from classes ? Would \resource mean the builtin type or a class name ?
Do you mean no class could be defined under \ ?
Syntax for union types ?
Regards
-----Message d'origine-----
De : Dennis Birkholz [mailto:dennis@birkholz.biz]
Envoyé : samedi 21 février 2015 07:06
À : internals@lists.php.net
Objet : Re: [PHP-DEV] [RFC] Reserve EVEN MORE types for PHP7Hi François,
Am 21.02.2015 um 03:03 schrieb François Laupretre:
I didn't consider defining builtin type hints as classes because :
I was not proposing using internal types as classes. I just want to
define a clean behavior for all kinds of types that may exist some time
in PHP. As no scalar type hints RFC has passed so far, we could also
define it in a clean way and just put the scalar types into , then we
can not have the conflicting classes there and have to use "function
foo(\int $c)" instead of "function foo(int $c)" which is a lot better
that switching type hints for classes to something like "function bar
(object(my\namespaced\class) $a)".
- I think it would be slower, and we need speed, but I agree, I did no test
I don't know this.
- no pre-defined namespace exists to handle this
There is \
- Reverting to the root namespace makes it twice slower. The case of
functions is nothing more than a hack to have a flawed design approved by all
means.Also you could just "use \int, \string;" on top of the file, than
"function foo(int $c)" is ok. In total, I think that is the BC-break
safe way to go, it will keep the door wide open for union types, etc.
without the worry of BC breaks. We could leave out all the hacky stuff
here. We could even use \PHP as the namespace to go.
- Storing builtin types in the root namespace would cause exactly the same
problem of sharing a naming space with user-defined names.No, because you can just move you classes into a namespace and add some
use statements to the top of the consumer files (with different
namespaces in use). With the current proposals, you have to invent new
names for you classes.
- and probably the most important one: the implementation is based upon
the ZPP layer, which allows internal and userland type hinting to follow
exactly the same logic.I consider this a detail that should not prevent a clean language
design. It may mean more work in the short time but I think this will
greatly increase the adoption rate if we can eliminate the BC break here.About namespaces : no type hinting feature is currently planned at the
namespace level, except the usual class resolution when a class name is used
as hint. Some may exist in the future as there will probably be more links
between built-in types and classes, such as specializing and combining builtin
types using a userland class or exposing builtin-types as classes.Thanks
Dennis
Hi François,
Please give more precise examples. I'm afraid I don't understand :
I try to clarify.
If you use \ as prefix for builtin types, how do you distinguish this from classes ? Would \resource mean the builtin type or a class name ?
Currently, all traits, classes and interfaces share a common symbol
table. So if a trait Foo exists in a namespace bar, not interface or
class with name Foo can also exist inside that namespace.
I now would not limit this symbol table to hold only the
class/interface/trait names but hold the names of all possible types.
(Types are classes, traits, interfaces, scalar types, arrays, etc)
If the integer type is named "int" in namespace , that means you can
not define a class/trait/interface/whatever in \ that is also named int.
Do you mean no class could be defined under \ ?
But any other class can be defined under \ as long as the name does not
conflict with other type names.
Syntax for union types ?
Union types where mentioned here several types e.g. for the numeric type
that would be defined somewhat like numeric = int|float but without a
specific syntax so far. These union types also look like a hack in the
moment and will get hardcoded somewhere. For each new union type that is
required, another name has to be excluded from being a valid class name.
If all these types also would only go into the \ namespace, there would
be nearly no BC break (at least with namespaced code).
The ability to define union types could even be exposed to the user
space to allow something like this:
namespace Foo;
class MyIncompatibleDateTime { ... }
union DateTime = \DateTime|MyIncompatibleDateTime;
class Whatever {
// Allow \DateTime and \Foo\MyIncompatibleDateTime here
function doWithDate(DateTime $date) { ... }
}
Another case are enum types that I saw on the list some time ago. The
names of the enum types should also go into the same symbol table.
From the point of view of a consumer/user of the language, it is kind of
inconsistent to have some type names that are limited in their scope
(class/trait/interface names are only valid inside their namespace) and
some type names that are global (primitive types like string/int/etc.).
We could argue now that it would be even better to put all primitive
types inside of \PHP so there would be absolutely no BC break when we
introduce them. We could also make very clean in the docs that users
should never ever define any types inside the \PHP namespace.
I understand that scalar types and classes are something different
inside the engine and I do not propose to remove all scalar types in
favor of class based primitive types. But the handling in the engine and
the resolution of a name in the PHP code are two different things. But
if we can allow scalar type names as type hints or return types, we
should also be able to put the names into the same namespaced symbol
table as we put class names. But I do not have a deep inside in the
inner workings of the engine code so this is only guesswork.
I hope my points are understandable. Thank you for your patience.
Greets
Dennis
Hi Dennis,
OK, I understand better :)
De : Dennis Birkholz [mailto:dennis@birkholz.biz]
Currently, all traits, classes and interfaces share a common symbol
table. So if a trait Foo exists in a namespace bar, not interface or
class with name Foo can also exist inside that namespace.I now would not limit this symbol table to hold only the
class/interface/trait names but hold the names of all possible types.
(Types are classes, traits, interfaces, scalar types, arrays, etc)
Arrays ??
If the integer type is named "int" in namespace , that means you can
not define a class/trait/interface/whatever in \ that is also named int.
The potential name clash is exactly the same. We want to define today keywords which won't conflict tomorrow with user class names defined yesterday. Also, how does the user know which types are currently defined, let alone those that will be in the future ? Sorry, it just moving the problem, not solving it.
Union types where mentioned here several types e.g. for the numeric type
that would be defined somewhat like numeric = int|float but without a
specific syntax so far.
What you show is not exactly union types. It is union type + alias, which is different. I intend to support a syntax like 'function str_replace(string|array $search,...', using no alias. That's what I'm asking a syntax for. No problem with type aliases but my primary intent is not to merge both features.
For each new union type that is
required, another name has to be excluded from being a valid class name.
If all these types also would only go into the \ namespace, there would
be nearly no BC break (at least with namespaced code).
Everything is in 'at least'.
Sorry, but similar to suggesting lowercase-only types. That's conventions only. We cannot base on this.
class MyIncompatibleDateTime { ... }
union DateTime = \DateTime|MyIncompatibleDateTime;
Defining a new kind of element in a class is huge work as there are implications everywhere. I'd prefer to stick with existing concepts.
class Whatever {
// Allow \DateTime and \Foo\MyIncompatibleDateTime here
function doWithDate(DateTime $date) { ... }
Readability limited to 5 minutes. One year later, of for your colleague, everyone will guess you're referencing the a DateTIme class.
Another case are enum types that I saw on the list some time ago. The
names of the enum types should also go into the same symbol table.
Enum is just a kind of specialized type. These will probably exist in the future, but I don't know which form they will take.
From the point of view of a consumer/user of the language, it is kind of
inconsistent to have some type names that are limited in their scope
(class/trait/interface names are only valid inside their namespace) and
some type names that are global (primitive types like string/int/etc.).
Probably but where do we stop ? Do you want to change syntax to use \PHP\function, \PHP\for, \PHP\switch everywhere in your code ? It would be useful too as it would allow to redefine language behavior from userland, but I guess we wouldn't have any user more to use the feature.
We could argue now that it would be even better to put all primitive
types inside of \PHP so there would be absolutely no BC break when we
introduce them. We could also make very clean in the docs that users
should never ever define any types inside the \PHP namespace.
The same. Doc is just conventions. Cannot base grammar on this.
I understand that scalar types and classes are something different
inside the engine and I do not propose to remove all scalar types in
favor of class based primitive types.
No. If we ever do it, both cannot coexist. Way too complex for the user and to implement.
But the handling in the engine and
the resolution of a name in the PHP code are two different things. But
if we can allow scalar type names as type hints or return types, we
should also be able to put the names into the same namespaced symbol
table as we put class names. But I do not have a deep inside in the
inner workings of the engine code so this is only guesswork.
In terms of internal implementation, adding another type in the symbol table shared by classes, interfaces, and traits is very complex work. The reason is that there is no real symbol type, as it was done incrementally. Engine behavior is based on a set of binary flags attached to each entry : is_interface, is_abstract, is_trait... Sometimes, these are not checked at all, this is for example the case with autoloaders. They don't have specialized behavior for interfacs and traits, so they don't check anything. Sometimes, the code distinguishes traits, sometimes abstract classes... Magic methods don't even have special flags. Most are recognized by strcmp()
when needed ! So, adding a new (virtual) type in such a table is very complex because there's no room for it. The only way is to add an additional is_type_hint flag and go modifying the code everything this should cause different behavior, e.g. almost everywhere. And changing this to define 'real' symbol types would be still more complex and would be rejected because it would slow down the interpreter.
So, no perfect solution here...
Thanks for your suggestions. I'll resume my position by saying that, from all you suggested, the only possible option, IMO, is to force the user to add a specific reserved prefix every time he uses a builtin type hint, or add a use clause at the beginning of each file. This alone would remove the RFC any chance to pass, even if I was strongly in favor of it. If I add the extreme implementation complexity and potential slow performance, I'd be dead 5 min after proposing it :)
Don't get me wrong. I appreciate your suggestions, but I don't think it's possible. As I previously said, additional features may be attached to namespaces, but probably as links with classes. But keep sending suggestions, I'm always interested in original ideas.
Thanks
François
Announcing this in its own thread:
https://wiki.php.net/rfc/reserve_even_more_types_in_php_7This RFC acts as an addition to Levi's
https://wiki.php.net/rfc/reserve_more_types_in_php_7 by creating a
forum for voting on additional types not included in his RFC:
resource, object, scalar, mixed, numericFrom the RFC:
“resource” “object” “scalar” “mixed” “numeric”
"... prohibits their usage as class, interface and trait names."
This is such a major BC break.
One thing we must do before even considering non required names is to
actually check every major apps, frameworks or libraries. If we can
avoid a date/datetime clash again, that would be awesome ;)
--
Pierre
@pierrejoye | http://www.libgd.org
Announcing this in its own thread:
https://wiki.php.net/rfc/reserve_even_more_types_in_php_7This RFC acts as an addition to Levi's
https://wiki.php.net/rfc/reserve_more_types_in_php_7 by creating a
forum for voting on additional types not included in his RFC:
resource, object, scalar, mixed, numeric
From the RFC:“resource” “object” “scalar” “mixed” “numeric”
"... prohibits their usage as class, interface and trait names."
This is such a major BC break.
One thing we must do before even considering non required names is to
actually check every major apps, frameworks or libraries. If we can
avoid a date/datetime clash again, that would be awesome ;)
"resource" is problematic as that is the proper name for "the thing that
corresponds to a URL" in REST. I would be shocked if there aren't
classes named Resource (namespaced or not) floating around in web
services code. I actually started writing one myself at one point on
the side but got distracted by something else shiny...
--Larry Garfield
Hi Larry,
That's OK. Let's remove 'resource'.
Anyway, I already explained why, IMO, the approach of reserving keywords is flawed from the beginning. I'll explain again and propose an alternative in the upcoming STH RFC.
Once we have a solution for the underlying issue with a planned solution, we can start reserve names for the interim period if it is still needed.
Regards
François
Hi all,
Announcing this in its own thread:
https://wiki.php.net/rfc/reserve_even_more_types_in_php_7This RFC acts as an addition to Levi's
https://wiki.php.net/rfc/reserve_more_types_in_php_7 by creating a
forum for voting on additional types not included in his RFC:
resource, object, scalar, mixed, numeric
We should have reserved these. IMHO.
Yes, it breaks. However, sooner is better.
People don't just use PHP7. We may try to promote these
changes now. We still have time.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
2015-02-21 1:23 GMT+01:00 Yasuo Ohgaki yohgaki@ohgaki.net:
Hi all,
Announcing this in its own thread:
https://wiki.php.net/rfc/reserve_even_more_types_in_php_7This RFC acts as an addition to Levi's
https://wiki.php.net/rfc/reserve_more_types_in_php_7 by creating a
forum for voting on additional types not included in his RFC:
resource, object, scalar, mixed, numericWe should have reserved these. IMHO.
Yes, it breaks. However, sooner is better.People don't just use PHP7. We may try to promote these
changes now. We still have time.Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Resource is used quite often:
https://github.com/search?l=php&q=class+Resource&ref=searchresults&type=Code&utf8=%E2%9C%93
Unfortunately, GitHub doesn't allow a search for "class Resource " for
better results.
Google knows about 600 occurrences:
https://www.google.de/?#q=site:github.com+%22class+resource%22+php
One more popular example usage:
https://github.com/phacility/phabricator/blob/master/externals/balanced-php/src/Balanced/Resource.php
Just to throw some numbers in.
Regards, Niklas
Hi all,
2015-02-21 1:23 GMT+01:00 Yasuo Ohgaki yohgaki@ohgaki.net:
Hi all,
Announcing this in its own thread:
https://wiki.php.net/rfc/reserve_even_more_types_in_php_7This RFC acts as an addition to Levi's
https://wiki.php.net/rfc/reserve_more_types_in_php_7 by creating a
forum for voting on additional types not included in his RFC:
resource, object, scalar, mixed, numericWe should have reserved these. IMHO.
Yes, it breaks. However, sooner is better.People don't just use PHP7. We may try to promote these
changes now. We still have time.Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.netResource is used quite often:
https://github.com/search?l=php&q=class+Resource&ref=searchresults&type=Code&utf8=%E2%9C%93
Unfortunately, GitHub doesn't allow a search for "class Resource " for
better results.Google knows about 600 occurrences:
https://www.google.de/?#q=site:github.com+%22class+resource%22+php
One more popular example usage:Just to throw some numbers in.
We may buy some time.
We may announce it by PHP 7.0. (E_STRICT perhaps?)
Introduce new reserved words in PHP 7.X. (E_ERROR/E_COMPILE_ERROR whichever
is appropriate)
Sooner announcement is better, then introduce.
It would work better.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net