php spl_autoload 不适用于语法错误的命名空间

标签 php namespaces syntax-error

我从这个例子中得到
http://www.php.net/manual/ru/function.spl-autoload.php#92767

但这会导致错误
* fatal error :spl_autoload() [function.spl-autoload]:第 18 行无法在 C:\my_projects\site.local\www\index.php 中加载类空间*

/index.php

// Your custom class dir
define('CLASS_DIR', 'oop/classes');

// Add your class dir to include path
set_include_path(get_include_path().PATH_SEPARATOR.CLASS_DIR);


// You can use this trick to make autoloader look for commonly used "My.class.php" type filenames
spl_autoload_extensions('.class.php');

// Use default autoload implementation
spl_autoload_register();

new space/my;

/oop/classes/space/my.class.php
namespace space;
class my{
  public function __construct{
    var_dump('space class was here!');
  }
}

我知道 PSR-0,但就我而言,我需要了解内置函数的工作原理

最佳答案

new space/my;

应该
new space\my;

注意:您错过了 ()__constructmy.class.php

关于php spl_autoload 不适用于语法错误的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12107161/

相关文章:

php - 在不使用事件的情况下按顺序排序

python - 如何初始化一个 python 对象并在其他模块之间共享?

r - 如何找出我的 R 对象来自哪个库?

javascript - javascript如果嵌套错误,则嵌套一行 “: expected”

javascript - 语法错误 : "Unexpected token <" in Web Console

php - 将变量从表单传递到函数

php - 从 .PHP 文件运行 BASH 脚本

php - mail() php 不以 html 格式发送

c# - 无法解析 System.Drawing.Bitmap 和 System.Drawing.ImageConverter

python - 奇怪的语法错误,我不知道如何解决