Take the State of PHP 2026 Survey →

PHP Namespace in core View as Markdown

Declined
Authors
Michał Brzuchalski brzuchal@php.net, George Peter Banyard girgias@php.net
Date
2020-03-25
Version
1.2.0
Source
wiki.php.net/rfc/php-namespace-in-core

Vote

Accept PHP namespace in core RFC? closed
Yes
19
No
24
43 voters
alec Yes 2020-05-29 04:56
asgrim Yes 2020-05-22 09:46
ashnazg No 2020-06-02 15:22
beberlei Yes 2020-05-25 08:04
brzuchal Yes 2020-05-22 06:11
bwoebi No 2020-05-22 09:16
carusogabriel No 2020-05-22 06:43
danack No 2020-05-26 15:13
daverandom Yes 2020-05-28 10:44
derick No 2020-05-30 10:10
dmitry No 2020-05-22 06:19
galvao No 2020-05-22 17:52
geekcom Yes 2020-05-29 14:06
girgias Yes 2020-05-22 11:42
guilhermeblanco Yes 2020-05-22 16:00
jasny No 2020-06-02 22:56
jbnahan Yes 2020-05-27 07:31
jhdxr Yes 2020-05-24 14:35
kalle No 2020-05-22 06:15
kguest No 2020-05-22 07:24
kocsismate Yes 2020-05-22 13:48
laruence No 2020-05-22 17:29
marandall Yes 2020-05-22 08:02
marcio No 2020-05-22 17:56
mcmic Yes 2020-06-03 09:43
nicolasgrekas No 2020-05-22 07:44
ocramius Yes 2020-05-22 17:33
patrickallaert No 2020-06-04 11:02
pmjones Yes 2020-05-22 12:16
ramsey Yes 2020-05-28 18:52
rasmus No 2020-05-28 04:53
remi No 2020-05-22 10:01
reywob Yes 2020-05-22 11:53
salathe No 2020-05-22 08:10
sergey Yes 2020-05-25 08:08
stas No 2020-05-22 16:51
svpernova09 No 2020-05-29 16:47
tandre No 2020-06-01 13:57
trowski No 2020-05-22 14:14
villfa No 2020-05-30 23:02
wyrihaximus Yes 2020-06-02 21:15
yunosh No 2020-05-27 06:29
zimt No 2020-06-03 13:39

Discussions on the mailing list

[RFC][DISCUSSION] PHP Namespace in core
· 19 messages
[RFC][VOTE] PHP Namespace in core
· 8 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:52 UTC

Introduction

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 paves the way to reduce the usage of the global namespace as “PHP”'s namespace.

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.

Features which could benefit from the PHP namespace

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 a situation where symbols under the \PHP namespace are not always available in PHP.

A small concrete example

Currently debug_backtrace() produces an array of arrays. An object oriented API could introduce the Frame 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.

Proposal

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

No backwards incompatible changes as only new classes/symbols would be introduces under the \PHP namespace.

Proposed PHP Version

PHP 8.0.

Concerns about inconsistent use

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.

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.

Future scope

Providing new core APIs building on new features introduces in PHP, such as:

  • I/O API using exceptions instead of warnings in case of failure
  • 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

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.

Vote: Accept PHP namespace in core RFC? — Yes: 19 · No: 24 (closed)

Patches and Tests

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 SplQueue extends SplDoublyLinkedList meaning SplQueue inherits the push() and pop() methods from SplDoublyLinkedList.

Therefore, if a user decides to use these methods instead of the designated enqueue() and dequeue() 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.