1

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 Answer 1

1

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');
Sign up to request clarification or add additional context in comments.

5 Comments

Flawk uses composer. So just include vendor/autoload.php.
According to the documentation, it should: http://php.net/manual/en/language.namespaces.importing.php
@Evert: So, I have to add a composer.json file first in the root?
@KoenDG depends on if you installed the library as a composer dependency, or if you just did a git clone. If it's the latter, you can simply install composer and run composer install in the same directory as composer.json.
@Evert I got it initially as a git clone. I copied the FlawkApi folder to my documentroot and also the composer.json file, which I also ran an install on. I'll check tomorrow what happens if I only import the composer.json file and run an install on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.