Search code examples
phpnamespacesspl

Using SPLFixedArray in namespace


I have a namespace declared as such:

namespace MySpace {

    $array = new SPLFixedArray();

}

Error I get is:

Fatal error: Class 'MySpace\SplFixedArray' not found in C:\xampp\htdocs\private\config.php on line 25

Is there a namespace defined for all SPL functions, or am I doing something incorrect here? scratches head


Solution

  • To use classes from the global namespace, prefix them with the namespace separator:

    $array = new \SplFixedArray;
    

    Or alias them like any other namespaced class:

    use \SplFixedArray;
    // ...
    $array = new SplFixedArray;