作曲家PSR-4自动加载器"未找到课程"错误

时间:2018-03-25 14:29:27

标签: php namespaces zend-framework3 autoloader psr-4

我尝试添加项目目录路径中不存在的DieEcho类。但是当我尝试在index.php文件中实现该类时得到错误。:

  

致命错误:未捕获错误:类' Trzczy \ Debug \ DieEcho' /home/j/Projects/project84/public/index.php:8中找不到堆栈跟踪:第8行/home/j/Projects/project84/public/index.php中引发#0 {main}



目录树是这样的:

├── debug
│   └── php
│       └── DieEcho.php
└── project84
    ├── composer.json
    └── public
        └── index.php



我运行composer dump-autoload,因此 autoload_psr4.php 中的条目出现了:

j@debian:~/Projects/project84$ cat ../../vendors/project84/composer/autoload_psr4.php 
<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir)).'/Projects/project84';

return array(
    //(...)
    'Trzczy\\Debug\\' => array($baseDir . '/../debug/php'), //the entry
    //(...)
);
j@debian:~/Projects/project84$ 



DieEcho.php 上课:

j@debian:~/Projects/project84$ cat ../debug/php/DieEcho.php 
<?php

namespace Trzczy\Debug;
class DieEcho
{
    //(...)
}
j@debian:~/Projects/project84$ 



我尝试以这种方式在 index.php 中实现该类:

j@debian:~/Projects/project84$ cat public/index.php 
<?php
use Zend\Mvc\Application;
use Zend\Stdlib\ArrayUtils;
use Trzczy\Debug\DieEcho;

error_reporting(-1);
ini_set('display_errors', true);
new DieEcho;
    //(...)



更新

composer.json

j@debian:~/Projects/project84$ cat composer.json 
{
    "config": {
        "vendor-dir": "../../vendors/project84"
    },
    //(...)
    "autoload": {
        "psr-4": {
            "Application\\": "module/Application/src/",
            "Trzczy\\Debug\\": "../debug/php/"
        }
    },
    //(...)
}
j@debian:~/Projects/project84$ 

我错了什么?这是在zend框架3项目中,但我不知道这些信息是否重要。

1 个答案:

答案 0 :(得分:0)

原因是v := *cnf.LcInfoLog["index"] log.Println("ABOUT LOCATION: ", v.FileLogPtr) 的包含是在课程实施后放置的。当我在包含autoload.php之后移动实现时,它就成功了。感谢@Magnus Eriksson评论。