Keywords In Namespaces

<?php

// PHP 8.0+ OK
// PHP 8.0- KO

namespace if\then\else {}

Since PHP 8.0, it is possible to use PHP keywords in namespaces.

In PHP 8.0, namespaces are processed independently, for their literal value. Before then, each namespace level was a distinct token, separated by the namespace separator: PHP keyword would then run into a processing conflict.

The last keyword that one can’t still use in a namespace is namespace, when used as the first part of the namespace : it is later replaced dynamically by the current namespace.

See Also

PHP Features

Last updated: 14 July 2026