dongne1560 2013-04-26 10:48
浏览 54
已采纳

PHP使用语句失败

I wanted to try out the FlawkApi library and copied the sample page for Steam accounts.

PHP is generating an error however:

Fatal error: Class 'FlawkApi\Services\Steam' not found in C:\xampp\htdocs\SteamAccount\index.php on line 18

The code in question is this:

use FlawkApi\Services\Steam;

// include bootstrap
require_once (__DIR__.'/bootstrap.php');

// initiate Steam with example gamerid and httpClient
$FlawkApi = new Steam($gamerIds['steam']['id'], $httpClientProvider());

That last line is line 18.

Bootstrap.php holds this:

// error reporting on
error_reporting(E_ALL);
ini_set('display_errors', 1);

// include some example gamer ids
require_once (__DIR__.'/init.php');

And init.php holds this(modified ID here, real ID is in the actual code):

$gamerIds = array(
    'steam' =>
    array(
        'id' => 'myId'
    )
);

$httpClientProvider = function() {
            return new \FlawkApi\Common\Http\Client\FlawkClient();
        };

This is a simple use statement that PHP is falling over. My PHP version is 5.4.7, installed from the latest XAMPP version.

Does anyone know what this wouldn't work?

EDIT: initialized the composer.json, it created the vendor folder. I then required vendor/autoload.php, but it still generates the same error.

EDIT2: Here's a screenshot of the folder structure and the composer.json file: enter image description here

  • 写回答

1条回答 默认 最新

  • dongliao1948 2013-04-26 10:55
    关注

    I think you can use spl_autoload_register to register function which can load the class if class is not found.

    e.g

    function my_autoloader($class) {
       if(file_exists(__DIR__ . $class . ".php"))
            require_once(__DIR__ . $class . ".php");
    }
    
    spl_autoload_register('my_autoloader');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥66 换电脑后应用程序报错
  • ¥50 array数据同步问题
  • ¥15 pic16F877a单片机的外部触发中断程序仿真失效
  • ¥15 Matlab插值拟合差分微分规划图论
  • ¥15 keil5 target not created
  • ¥15 C/C++数据与算法请教
  • ¥15 怎么找志同道合的伙伴
  • ¥20 如何让程序ab.eXe自已删除干净硬盘里的本文件自己的ab.eXe文件
  • ¥50 爬虫预算充足,跪巨佬
  • ¥15 滑块验证码拖动问题悬赏