Domanda

Why this is returning Fatal error: Class 'Mynamespace\String' not found in ...:

set_include_path(get_include_path().PATH_SEPARATOR.'library/');

spl_autoload_extensions('.php');

spl_autoload_register();

Mynamespace\String::myfunc('Test');

My library/String.php is:

<?php

namespace Mynamespace;

class String
{
    static function myfunc($needle)
    {
        echo $needle;
    }

Please not if I remove the namespace it works fine.

È stato utile?

Soluzione

spl_autoload_register() without params registers just spl_autoload().

And that default autoloader does not transpose namespaces onto directory names or anything. It just lowercases the received class name, and appends a .php suffix. Therefore namespaced classes will only work on Windows, accidentally.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top