kreait / firebase-php

Unofficial Firebase Admin SDK for PHP
https://firebase-php.readthedocs.io/
MIT License
2.26k stars 429 forks source link

Fatal error: Class 'Kreait\Firebase\ServiceAccount' #250

Closed kiam123 closed 6 years ago

kiam123 commented 6 years ago

How to fix this problem? PHP Fatal error: Class 'Kreait\Firebase\ServiceAccount' not found in E:\xampp\htdocs\firebase\index.php on line 8

Fatal error: Class 'Kreait\Firebase\ServiceAccount' not found in E:\xampp\htdocs\firebase\index.php on line 8

php version

PHP 5.6.31 (cli) (built: Jul 5 2017 22:25:43) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies  

Composer version

Composer version 1.6.5 2018-05-04 11:44:59  

index.php

<?php

require_once './vendor/autoload.php';

use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/secret/recommeded-food-system-9b624af0b272.json');

$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->create();

$database = $firebase->getDatabase();

die(print_r($database));

composer.json

{
    "name": "vendor/slash",
    "description": "PHP Toturial",
    "type": "project",
    "license": "GNU3",
    "minimum-stability": "dev",
    "require": {}
}
jeromegamez commented 6 years ago

It looks like you haven't added the SDK as a dependency to your composer.json.

As you're on PHP 5.6, so you can only use Release 3.x - so your composer.json should look like this:

{
    "name": "vendor/slash",
    "description": "PHP Toturial",
    "type": "project",
    "license": "GNU3",
    "minimum-stability": "dev",
    "require": {
        "kreait/firebase-php": "^3.9.3"
    }
}
kiam123 commented 6 years ago

@jeromegamez i change my composer.json and type composer install, but show this problem composer.json

{
    "name": "vendor/slash",
    "description": "PHP Toturial",
    "type": "project",
    "license": "GNU3",
    "minimum-stability": "dev",
    "require": {
        "kreait/firebase-php": "^3.9.3"
    }
}

image

jeromegamez commented 6 years ago

Ooops, sorry, my fault! For PHP 5.6, you need ^1.2.2 (Documentation at https://firebase-php.readthedocs.io/en/1.2.2/ )

kiam123 commented 6 years ago

same the error PHP Fatal error: Class 'Kreait\Firebase\ServiceAccount' not found in E:\xampp\htdocs\firebase\index.php on line 8

Fatal error: Class 'Kreait\Firebase\ServiceAccount' not found in E:\xampp\htdocs\firebase\index.php on line 8

index.php

<?php

require_once './vendor/autoload.php';

use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/secret/recommeded-food-system-9b624af0b272.json');

$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->create();

$database = $firebase->getDatabase();

die(print_r($database));

composer.json

{
    "name": "vendor/slash",
    "description": "PHP Toturial",
    "type": "project",
    "license": "GNU3",
    "minimum-stability": "dev",
    "require": {
        "kreait/firebase-php": "^1.2.2"
    }
}
jeromegamez commented 6 years ago

You'll also have to actually read the documentation :) - the usage is different in release 1.x (it's an old release). https://firebase-php.readthedocs.io/en/1.2.2/

Also, you will not have access to most of the features of release 4.x. - I highly recommend upgrading your PHP version to at least 7.0 - PHP 5.6 is not a supported PHP version anymore.

jeromegamez commented 6 years ago

Closing this as it's not a bug with the SDK itself, but feel free to add further comments/findings to share with others!

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.