rfc:class-like_primitive_types
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:class-like_primitive_types [2016/12/19 21:12] – ajf | rfc:class-like_primitive_types [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 8: | Line 8: | ||
===== Background ===== | ===== Background ===== | ||
- | PHP has a small set of built-in types of value: null, Boolean, integer, float, string, array, object and resource. These types are known as “primitive” types, because they are built-in to the language. Of these, objects are special. Objects, themselves | + | PHP has a small set of built-in types of value: null, Boolean, integer, float, string, array, object and resource. These types are known as “primitive” types, because they are built-in to the language. Of these, objects are special. Objects, themselves |
Since their introduction in PHP 3.0, classes and objects have gained several features that are exclusive to them, which the other primitive types consequently cannot make use of. These features include instance and static methods, properties, class constants, interface implementation, | Since their introduction in PHP 3.0, classes and objects have gained several features that are exclusive to them, which the other primitive types consequently cannot make use of. These features include instance and static methods, properties, class constants, interface implementation, | ||
Line 62: | Line 62: | ||
* < | * < | ||
* < | * < | ||
+ | * < | ||
**FIXME:** What do I do about reflection? | **FIXME:** What do I do about reflection? | ||
+ | |||
+ | === Serializable and resources === | ||
+ | |||
+ | The resource type will not implement the < | ||
==== Primitive type class hierarchy ==== | ==== Primitive type class hierarchy ==== | ||
Line 70: | Line 75: | ||
<code php> | <code php> | ||
- | final class null implements Serializable, | + | /* There is no shadow |
- | public function __toString() { /* ... */ } | + | |
- | public function serialize() { /* ... */ } | + | |
- | public function unserialize($serialized) { /* ... */ } | + | |
- | public function jsonSerialize() { /* ... */ } | + | |
- | } | + | |
final class bool implements Serializable, | final class bool implements Serializable, | ||
public function __toString() { /* ... */ } | public function __toString() { /* ... */ } | ||
Line 110: | Line 111: | ||
} | } | ||
} | } | ||
- | final class resource | + | final class resource { |
public function __toString() { /* ... */ } | public function __toString() { /* ... */ } | ||
- | public function serialize() { /* ... */ } | ||
- | public function unserialize($serialized) { /* ... */ } | ||
} | } | ||
</ | </ | ||
Line 132: | Line 131: | ||
==== To Existing Extensions ==== | ==== To Existing Extensions ==== | ||
- | This does not impact existing extensions, their view of the world is unchanged and the other primitive types are still primitives. | + | This does not impact existing extensions: their view of the world is unchanged and the primitive types other than objects |
**FIXME:** Reflection. | **FIXME:** Reflection. | ||
Line 143: | Line 142: | ||
**FIXME:** Reflection, Opcache. | **FIXME:** Reflection, Opcache. | ||
+ | |||
+ | ==== Should null have a shadow class? ==== | ||
+ | |||
+ | Or in other words, should these features be extended to < | ||
+ | |||
+ | < | ||
+ | |||
+ | Would methods like < | ||
+ | |||
+ | In JavaScript, '' | ||
+ | |||
+ | This RFC currently chooses to omit null from the extension of most features of objects to the other types, but excepts < | ||
+ | |||
+ | ==== Should resource be supported? ==== | ||
+ | |||
+ | Resource is a legacy type that could be wholly replaced by objects in future. Extending these features to this type would be further entrenching it and contrary to the goal of its eventual removal. | ||
+ | |||
+ | In particular, < | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 152: | Line 169: | ||
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:// | + | One of these would be [[http:// |
+ | |||
+ | It also means we can easily introduce new superclasses of our other primitive types. For example, a new < | ||
+ | |||
+ | 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, | ||
- | It also means we can easily introduce new superclasses of our other primitive types. For example, a new <php>\Number</ | + | <php>instanceof</ |
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== |
rfc/class-like_primitive_types.1482181932.txt.gz · Last modified: 2017/09/22 13:28 (external edit)