Both sides previous revisionPrevious revisionNext revision | Previous revision |
rfc:class-like_primitive_types [2016/12/19 22:04] – ajf | rfc:class-like_primitive_types [2017/09/22 13:28] (current) – external edit 127.0.0.1 |
---|
In JavaScript, ''null'' does not have any properties or methods, but ''true'' and ''false'' do. In contrast, Python's ''None'' (its equivalent to null) //does// have properties and methods, albeit only magic methods. | In JavaScript, ''null'' does not have any properties or methods, but ''true'' and ''false'' do. In contrast, Python's ''None'' (its equivalent to null) //does// have properties and methods, albeit only magic methods. |
| |
This RFC currently chooses to omit null from support by most of these features. | This RFC currently chooses to omit null from the extension of most features of objects to the other types, but excepts <php>instanceof null</php> because it lacks the same potential to create errors. |
| |
==== Should resource be supported? ==== | ==== Should resource be supported? ==== |
The extension of these features to the other primitive types opens up a number of future possibilities. | The extension of these features to the other primitive types opens up a number of future possibilities. |
| |
One of these would be [[http://nikic.github.io/2014/03/14/Methods-on-primitive-types-in-PHP.html|methods on the other primitive types]] (and also properties). This could make string and array manipulation more convenient, and additionally provides an opportunity for a fresh start versus the old standard string and array functions, which have notoriously inconsistent naming and parameter orders. | One of these would be [[http://nikic.github.io/2014/03/14/Methods-on-primitive-types-in-PHP.html|introducing new methods on the other primitive types]] (and also properties). This could lend string and array manipulation the convenience of method calls, and would provide an opportunity for a fresh start versus PHP's existing string and array functions, which have notoriously inconsistent naming and parameter orders. |
| |
It also means we can easily introduce new superclasses of our other primitive types. For example, a new <php>\Number</php> type superclassing <php>int</php> and <php>float</php>, or a new <php>\Scalar</php> type superclassing everything except objects and arrays. | It also means we can easily introduce new superclasses of our other primitive types. For example, a new <php>\Number</php> type superclassing <php>int</php> and <php>float</php>, or a new <php>\Scalar</php> type superclassing everything except objects and arrays. Such superclasses could potentially be extended also by user-defined classes. |
| |
| Likewise, we could introduce new interfaces implemented by our other primitive types. One potential use for this is operator overloading. PHP could add an interface for number-like classes, which when implemented, would allow use of the number operators (''+ - * /'' etc.) with objects of that class. That interface could itself be implemented by PHP's own <php>int</php> and <php>float</php> types. |
| |
| <php>instanceof</php> could potentially support pseudo-types like <php>callable</php>. |
| |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== |