rfc:namespaces-for-internal-classes

This is an old revision of the document!


Request for Comments: How to write RFCs

  • Version: 1.0
  • Date: 2008-03-06
  • Author: Lars Strojny lstrojny@php.net
  • Status: Work in progress
  • First Published at: none

Introduction

This RFC discusses the transition to real namespaces for internal classes in e.g. ext/spl.

Why should we use namespaces for internal classes?

Currently internal classes are inconsistently named. Just take a look at SPL:

  • RecursiveIterator
  • RecursiveIteratorIterator
  • RecursiveRegexIterator
  • RegexIterator
  • RuntimeException
  • SeekableIterator
  • SimpleXMLIterator
  • SplFileInfo
  • SplFileObject
  • SplObjectStorage
  • SplObserver

Some of the classes in ext/spl are prefixed with “Spl”, some are not. To avoid naming collisions and as a structural element, namespaces were introduced in PHP 5.3. This gives us a chance to move all the Spl-classes in appropriate namespaces. Take a look at the following transitions:

  • RecursiveIterator: Spl::Iterator::Recursive
  • RecursiveIteratorIterator: Spl::Iterator::Recursive::Iterator
  • RecursiveRegexIterator: Spl::Iterator::Recursive::RegexIterator
  • RegexIterator: Spl::Iterator::Regex
  • RuntimeException: Spl::Exception::Runtime
  • SimpleXMLIterator: Spl::Iterator::SimpleXML
  • SplObserver: Spl::Observer::Observer
  • SplSubject: Spl::Observer::Subject
  • SplFileInfo: Spl::File::Info
  • SplFileObject: Spl::File::Object
  • SeekableIterator: Spl::Iterator::Seekable

Proposal and Patch

The hardest part of the proposal is to find a way not to break backwards compatibility. The old names will be present in PHP 5.3 and will be removed in PHP 6.

rfc/namespaces-for-internal-classes.1213726703.txt.gz · Last modified: 2017/09/22 13:28 (external edit)