duanqi5114 2019-06-11 18:18
浏览 294

使用psr-4时,使用composer进行自动加载不起作用

I have an issue running a function when use psr-4 autoloading.

When i declare directly which files should be in autoloading everything works fine. When i switch to psr-4 then i get log that the function is undefined.

src/cli.php:

namespace Php\Project1\Cli;

function run()
{
  ...
}

bin/brain-games:

#!/usr/bin/env php

<?php

$autoloadPath1 = __DIR__ . '/../../../autoload.php';
$autoloadPath2 = __DIR__ . '/../vendor/autoload.php';

if (file_exists($autoloadPath1)) {
    require_once $autoloadPath1;
} else {
    require_once $autoloadPath2;
}

use function Php\Project1\Cliun;
run();

composer.json:

"autoload": {
      "psr-4": {
        "Php\\Project1\\": "src/"
      }
  },

The error that i get is:

PHP Fatal error:  Uncaught Error: Call to undefined function Php\Project1\Cliun() in /home/arkadiy/php-project1/bin/brain-games:15
Stack trace:
#0 {main}
  thrown in /home/arkadiy/php-project1/bin/brain-games on line 15

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本