rfc:php-namespace-in-core

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:php-namespace-in-core [2020/04/03 14:04]
girgias Major rewrite
rfc:php-namespace-in-core [2020/06/04 11:51] (current)
brzuchal closed voting
Line 1: Line 1:
 ====== PHP RFC: PHP Namespace in core ====== ====== PHP RFC: PHP Namespace in core ======
-  * Version: ​0.9+  * Version: ​1.2.0
   * Date: 2020-03-25   * Date: 2020-03-25
   * Author: Michał Brzuchalski <​brzuchal@php.net>,​ George Peter Banyard <​girgias@php.net>​   * Author: Michał Brzuchalski <​brzuchal@php.net>,​ George Peter Banyard <​girgias@php.net>​
-  * Status: ​Draft+  * Status: ​Declined
   * First Published at: http://​wiki.php.net/​rfc/​php-namespace-in-core   * First Published at: http://​wiki.php.net/​rfc/​php-namespace-in-core
  
 ===== Introduction ===== ===== Introduction =====
-The PHP project has reserved the right to use the ''​\PHP''​ namespace but has never acted upon starting to use it. We therefore ​suggest ​that core symbols which cannot be unbundled such as those related to the language/​parser/​interpreter ​may start using the ''​\PHP''​ namespace.+The PHP project has reserved the right to use the ''​\PHP''​ namespace but has never acted upon starting to use it. We therefore ​propose ​that core symbols which cannot be unbundled such as those related to the language/​parser/​interpreter ​must use ''​\PHP''​ namespace.
  
-This would provide a way to reduce the usage of the global namespace as "​PHP"'​s namespace ​and also provide a way to fix some fundamental misnaming.+This paves the way to reduce the usage of the global namespace as "​PHP"'​s namespace.
  
-Introduction of PHP namespace also as a way for gradual migration over renamed and marked as deprecated symbols reducing breaking changes. [Girgias Note: I'm not sure this sentence makes sense] +This is not a concrete proposal on how to structure the namespace or a proposal on re-aliasing ​classes to use the ''​\PHP''​ namespace. This is only an agreement that core classes or newly introduced symbols which are tightly coupled to the PHP engine ​must start using the ''​\PHP''​ namespace, e.g. for type prefixes.
- +
-This is not a concrete proposal on how to structure the namespace or a proposal on realising ​classes to use the ''​\PHP''​ namespace. This is only an agreement that core classes or newly introduced symbols which are tightly coupled to the PHP engine ​may start using the ''​\PHP''​ namespace, e.g. for type prefixes.+
  
 ===== Features which could benefit from the PHP namespace ===== ===== Features which could benefit from the PHP namespace =====
Line 20: Line 18:
   * The currently under discussion [[rfc:​attributes_v2|PHP RFC: Attributes v2]] could use the ''​\PHP''​ namespace for engine/​internal related attributes.   * The currently under discussion [[rfc:​attributes_v2|PHP RFC: Attributes v2]] could use the ''​\PHP''​ namespace for engine/​internal related attributes.
  
-As these sort of symbols are tied to the engine there is no risk that they will get unbundled from PHP core and moved to PECL. We note this as we aware that if a non core extension would use the ''​\PHP''​ namespace and gets unbundled and moved to PECL we would find ourselves in the situation where symbols under the ''​\PHP''​ namespace are always available in PHP.+As these sort of symbols are tied to the engine there is no risk that they will get unbundled from PHP core and moved to PECL. We note this as we are aware that if a non core extension would use the ''​\PHP''​ namespace and gets unbundled and moved to PECL we would find ourselves in situation where symbols under the ''​\PHP''​ namespace are not always available in PHP.
  
-==== A small toy-example ==== +==== A small concrete ​example ==== 
-Currently <​php>​debug_backtrace()</​php>​ produces ​and array of arrays. An object oriented API could introduce the <​php>​Frame</​php>​ class to hold details about each frame in the backtrace. As this would be an internal API using the ''​\PHP''​ namespace ​this would signal ​clear ownership and possibly limit the BC breaks for users which don't use the namespace feature of PHP.+Currently <​php>​debug_backtrace()</​php>​ produces ​an array of arrays. An object oriented API could introduce the <​php>​Frame</​php>​ class to hold details about each frame in the backtrace. As this would be an internal API using the ''​\PHP''​ namespace ​signals ​clear ownership and possibly limit the BC breaks for users which don't use the namespace feature of PHP.
  
-===== A chance to clean up poor design/​naming decisions ===== 
-Currently within the Reflection extension we have the following classes ''​ReflectionType''​ and ''​ReflectionNamedType''​ however their purpose isn't exacty to present a type. 
- 
-From PHP's type system perspective,​ a class is a type. Therefore, ''​ReflectionClass''​ not extending from ''​ReflectionType''​ could be seen as questionable. Thus the ''​ReflectionType''​ class acts more as a type constraint and renaming it to ''​ReflectionTypeConstraint''​ may be a good way to clarify it's concern. 
- 
-This RFC could allow us to redesign, with the benefit of hindsight, some of the core APIs provided by PHP. 
- 
-Continuing from the previous example we could alias ''​ReflectionType''​ to the more accurate ''​PHP\ReflectionTypeConstraint''​ class name, and possibly in the future introduce ''​PHP\ReflectionType''​ as the top reflector for all kinds of types which may be introduced in the future, e.g. Enums, Generics, etc. 
- 
-Another infamous example would be some of the data structures provides by the SPL extension. Indeed as <php> SplQueue extends SplDoublyLinkedList</​php>​ this means that <​php>​SplQueue</​php>​ inherits the <​php>​push()</​php>​ and <​php>​pop()</​php>​ methods from <​php>​SplDoublyLinkedList</​php>​ meaning that if you decide to use these functions instead of the designated <​php>​enqueue()</​php>​ and <​php>​dequeue()</​php>​ methods you get something which behave like a stack instead of a queue. 
- 
-Although some of these concerns may be fixed with the introduction of the [[https://​github.com/​nikic/​php-rfcs/​blob/​language-evolution/​rfcs/​0000-language-evolution.md|Language evolution]] RFC as this use case of the proposal is a redesign once, life with it's imperfection forever. We still believe this may be a valid use case. 
-  
 ===== Proposal ===== ===== Proposal =====
-Allow tightly coupled ​internal/​engine ​symbols with the PHP interpreter ​to use the ''​\PHP''​ namespace.+New features or symbols which are tightly coupled ​to the internals/​engine ​of the PHP interpreter ​must use the ''​\PHP''​ namespace ​starting from PHP 8.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
-No backwards incompatible changes as we would only introduce ​new classes under the ''​\PHP''​ namespace.+No backwards incompatible changes as only new classes/symbols would be introduces ​under the ''​\PHP''​ namespace.
  
 ===== Proposed PHP Version ===== ===== Proposed PHP Version =====
-Next PHP 8.0.+PHP 8.0.
  
-===== RFC Impact ​===== +===== Concerns about inconsistent use ===== 
-==== To SAPIs ==== +Various symbols which are widely used are located in the global namespace, classes such as ''​Closure''​ or ''​Generator''​ and interfaces such as ''​Countable'',​ ''​ArrayAccess'',​ and many others.
-None.+
  
-==== To Existing Extensions ==== +Although some of these fall into the category of being tightly tied to the engine and would land in the ''​\PHP''​ namespace under this proposal if newly introduced. We consider the long term advantage of using the namespace and the benefits it can provide as a an acceptable trade-off.
-None.+
  
-==== To Opcache ​==== +===== Future scope ===== 
-None.+Providing new core APIs building on new features introduces in PHP, such as:
  
-==== New Constants ==== +  * I/O API using exceptions instead of warnings in case of failure 
-None.+  * New data structures to replace SPL data structures, see Appendix for reasons why
  
 +Or revamping current ones:
 +  ​
 +  * Reflection, see Appendix for a use case 
 + 
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
- 
 The vote is a straight Yes/No vote requiring a 2/3 majority to accept the RFC. The vote is a straight Yes/No vote requiring a 2/3 majority to accept the RFC.
 +
 +===== Vote =====
 +Voting started on 2020-05-22 and will end on 2020-06-04 at 6:00 UTC.
 +<doodle title="​Accept PHP namespace in core RFC?" auth="​brzuchal"​ voteType="​single"​ closed="​true">​
 +   * Yes
 +   * No
 +</​doodle>​
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
 This RFC doesn'​t provide any changes. This RFC doesn'​t provide any changes.
  
 +===== Changelog =====
 +1.0.0: Initial version \\
 +1.1.0: New features must use the PHP engine, before this was merely a suggestion \\
 +1.2.0: Major rewrite, addressing concerns about inconsistent usage \\
 +
 +===== Appendix =====
 +==== SPL Data Structures ====
 +An infamous example is that <php> SplQueue extends SplDoublyLinkedList</​php>​ meaning <​php>​SplQueue</​php>​ inherits the <​php>​push()</​php>​ and <​php>​pop()</​php>​ methods from <​php>​SplDoublyLinkedList</​php>​.
 +
 +Therefore, if a user decides to use these methods instead of the designated <​php>​enqueue()</​php>​ and <​php>​dequeue()</​php>​ methods the behaviour obtained is the one of a stack instead of a queue.
 +
 +==== Reflection ====
 +Currently within the Reflection extension we have the following classes ''​ReflectionType''​ and ''​ReflectionNamedType''​ however their purpose isn't exactly to present a type.
 +
 +From PHP's type system perspective,​ a class is a type. Therefore, ''​ReflectionClass''​ not extending from ''​ReflectionType''​ could be seen as questionable. Thus the ''​ReflectionType''​ class acts more as a type constraint and renaming it to ''​ReflectionTypeConstraint''​ may be a good way to clarify it's concern.
 +
 +Thus, in a revamped Reflection extension one could imagine a more accurate ''​PHP\ReflectionTypeConstraint''​ to represent the current ''​ReflectionType''​ and introduce a new top reflector ''​PHP\ReflectionType''​ for all types current, and future. E.g Enums, Generics, etc.
rfc/php-namespace-in-core.1585922645.txt.gz · Last modified: 2020/04/03 14:04 by girgias