0
votes

I am using firebase as backend in php, but when i am calling "fromJsonFile" method of "ServiceAccount" i am getting bellow error:

Fatal error: Uncaught Error: Call to private method Kreait\Firebase\ServiceAccount::fromJsonFile() from context '' in C:\xampp\htdocs\wordpress\wp-content\plugins\firebase-connection.php:7 Stack trace: #0 C:\xampp\htdocs\wordpress\wp-content\plugins\sb-api\sb_api.php(31): include() #1 C:\xampp\htdocs\wordpress\wp-settings.php(362): include_once('C:\xampp\htdocs...') #2 C:\xampp\htdocs\wordpress\wp-config.php(90): require_once('C:\xampp\htdocs...') #3 C:\xampp\htdocs\wordpress\wp-load.php(37): require_once('C:\xampp\htdocs...') #4 C:\xampp\htdocs\wordpress\wp-admin\admin.php(34): require_once('C:\xampp\htdocs...') #5 C:\xampp\htdocs\wordpress\wp-admin\index.php(10): require_once('C:\xampp\htdocs...') #6 {main} thrown in C:\xampp\htdocs\wordpress\wp-content\plugins\firebase-connection.php on line 7

The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.

Here is my code:

<?php
require __DIR__.'/vendor/autoload.php';

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

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$firebase = (new Factory)
    ->withServiceAccount($serviceAccount)
    ->create();

$database = $firebase->getDatabase();

?>
2

2 Answers

0
votes

Can you tell us the version of the firebase-php that you are currently using?

If you are using version lower than 5.x please update to the latest version.

https://github.com/kreait/firebase-php

It is using php 7.2^. Current wordpress requires 7.3 so it must be updated to latest version

Here is the documentation as well.

https://firebase-php.readthedocs.io/en/latest/

I don't know exactly what the problem is but it seems the error says you can't access a private method, so you should access it by updating it to public or public static method.

0
votes

For ver 5.x

// @see https://firebase-php.readthedocs.io/en/5.2.0/troubleshooting.html
$factory = (new Factory)->withServiceAccount(__DIR__.'/google-service-account.json');

$database = $factory->createDatabase();

// if you want auth
//$auth = $factory->createAuth();