pollita

Sara Golemon

levim

Levi Morrison

Contents

PHP RFC: Reserve Even More Types in PHP 7

Proposal

This RFC adds to https://wiki.php.net/rfc/reserve_more_types_in_php_7 to prevents the use of the following additional words to be used as a class, interface or trait name:

  • “resource”
  • “object”
  • “scalar”
  • “mixed”
  • “numeric”

This RFC does not fully reserve them as keywords; it only prohibits their usage as class, interface and trait names. It also prevents them from being used in namespaces.

Rationale

Facilitate Future RFCs

Reserving these words in PHP 7 would allow for another RFC to add scalar types in a minor release such as PHP 7.1 (assuming they make no backwards compatibility breaks). Without reserving them now a future RFC would only be able to target major PHP versions such as version 8 since they would break backwards compatibility.

Disallowing Classes

Given that PHP has primitive types such as int, float, string and null it does not make sense for them to exist as classes, or if they do they should be provided by PHP itself.

Backward Incompatible Changes

This breaks any and all cases where these new reserved words are used in class, interface or trait names. It does not break any usages as function or method names or as class constants.

Unaffected PHP Functionality

This RFC does not change the way our current parameter and return type hints work. Support for these new reserved words as types for parameters or return types is beyond the scope of this RFC.

Future Scope

Potentially future RFCs could:

  • add explicit scalar type support for parameter and return types
  • add union types, such as int|false

Result

The following class names are now reserved:

  • “resource”
  • “object”
  • “mixed”
  • “numeric”

The following class names have not been reserved:

  • “scalar”

Patches and Tests

There is currently no implementation.

Votes

An option needs 50%+1 votes to win

Reserved Type: resource (69% approved)
User Vote
ajf Yes
bishop No
brianlmoon Yes
bwoebi No
danack Yes
datibbaw No
daverandom No
derick Yes
diegopires Yes
dm No
dmitry No
dragoonis Yes
eliw Yes
fredemmott Yes
guilhermeblanco Yes
hywan No
ircmaxell No
irker Yes
ivonascimento Yes
jedibc Yes
jgmdev Yes
jmikola Yes
joey Yes
jwage Yes
kalle No
kguest Yes
kinncj Yes
laruence No
lcobucci Yes
leigh No
levim No
lstrojny Yes
mbeccati Yes
mike No
mj Yes
nikic No
ocramius No
pauloelr Yes
pollita Yes
ramsey Yes
rdlowrey Yes
rdohms Yes
rmf Yes
salathe No
santiagolizardo Yes
sebastian Yes
seld Yes
stas No
stelianm Yes
subjective Yes
svpernova09 Yes
thekid No
timo Yes
toby Yes
yohgaki Yes
yunosh Yes
zeev Yes
zimt Yes
Reserved Type: scalar (64.2% approved)
User Vote
ajf Yes
bishop No
brianlmoon Yes
bwoebi No
danack No
datibbaw Yes
daverandom Yes
derick Yes
diegopires Yes
dm No
dmitry No
dragoonis Yes
eliw Yes
fredemmott Yes
guilhermeblanco Yes
hywan No
ircmaxell Yes
irker Yes
ivonascimento Yes
jedibc Yes
jgmdev Yes
jmikola Yes
joey Yes
jwage Yes
kalle No
kguest Yes
laruence No
lcobucci Yes
leigh No
levim No
lstrojny Yes
mbeccati No
mike No
mj Yes
nikic No
ocramius No
pauloelr Yes
pollita Yes
ramsey Yes
rdlowrey No
rdohms Yes
salathe No
santiagolizardo No
sebastian Yes
stas No
stelianm Yes
subjective Yes
svpernova09 Yes
thekid No
timo Yes
toby Yes
yohgaki Yes
zimt Yes
Reserved Type: object (81.8% approved)
User Vote
ajf Yes
bishop No
brianlmoon Yes
bwoebi No
danack Yes
datibbaw Yes
daverandom Yes
derick Yes
diegopires Yes
dm Yes
dmitry No
dragoonis Yes
eliw Yes
fredemmott Yes
guilhermeblanco Yes
hywan Yes
ircmaxell Yes
irker Yes
ivonascimento Yes
jedibc Yes
jgmdev Yes
jmikola Yes
joey Yes
jwage Yes
kalle No
kguest Yes
laruence No
lcobucci Yes
leigh Yes
levim Yes
lstrojny Yes
mbeccati Yes
mike No
mj Yes
nikic No
ocramius Yes
pauloelr Yes
pollita Yes
ramsey Yes
rdlowrey Yes
rdohms Yes
rmf Yes
salathe No
santiagolizardo Yes
sebastian Yes
stas No
stelianm Yes
subjective Yes
svpernova09 Yes
thekid No
timo Yes
toby Yes
yohgaki Yes
yunosh Yes
zeev Yes
Reserved Type: mixed (73.2% approved)
User Vote
ajf Yes
bishop No
brianlmoon Yes
bwoebi No
danack Yes
datibbaw Yes
daverandom Yes
derick Yes
diegopires Yes
dm Yes
dmitry No
dragoonis Yes
eliw Yes
fredemmott Yes
guilhermeblanco Yes
hywan No
ircmaxell Yes
irker Yes
ivonascimento Yes
jedibc Yes
jgmdev Yes
jmikola Yes
joey No
jwage Yes
kalle No
kguest Yes
laruence No
lcobucci Yes
leigh No
levim No
lstrojny Yes
mbeccati Yes
mike No
mj No
nikic Yes
ocramius Yes
pauloelr Yes
pollita Yes
ramsey Yes
rdlowrey Yes
rdohms Yes
salathe No
santiagolizardo No
sebastian Yes
seld Yes
stas No
stelianm Yes
subjective Yes
svpernova09 Yes
thekid No
timo Yes
toby Yes
yohgaki Yes
yunosh Yes
zeev Yes
zimt Yes
Reserved Type: numeric (78.6% approved)
User Vote
ajf Yes
andrey Yes
bishop No
brianlmoon Yes
bwoebi Yes
danack Yes
datibbaw Yes
daverandom Yes
derick Yes
diegopires Yes
dm Yes
dmitry No
dragoonis Yes
eliw Yes
fredemmott Yes
guilhermeblanco Yes
hywan No
ircmaxell Yes
irker Yes
ivonascimento Yes
jedibc Yes
jgmdev Yes
jmikola Yes
joey Yes
jwage Yes
kalle No
kguest Yes
laruence No
lcobucci Yes
leigh No
levim No
lstrojny Yes
mbeccati Yes
mike No
mj Yes
nikic Yes
ocramius Yes
pauloelr Yes
pollita Yes
ramsey Yes
rdlowrey Yes
rdohms Yes
salathe No
santiagolizardo No
sebastian Yes
seld Yes
stas No
stelianm Yes
subjective Yes
svpernova09 Yes
thekid No
timo Yes
toby Yes
yohgaki Yes
zeev Yes
zimt Yes