AtlasPublicPolicy/power-bi-embedded

PHP 8.0 Fatal Error: Non-static method Power_Bi_Oauth::get_token() cannot be called statically

Closed this issue · 9 comments

Embeds will not load in PHP 8.0. The following error is called:

Got error 'PHP message: PHP Fatal error:  Uncaught Error: Non-static method Power_Bi_Oauth::get_token() cannot be called statically in .../embed-power-bi/includes/class-power-bi.php:92

I was able to get the embeds to work again by changing this:
$returnObject = Power_Bi_Oauth::get_token();
to this:

$Power_Bi_Oauth = new Power_Bi_Oauth();
$returnObject = $Power_Bi_Oauth->get_token();

which also required that I set the constructor in class-power-bi-oauth.php to public instead of private.

This was enough to fix the reports so that they appear again, but I am essentially hacking away in there and have no idea if this is a quality solution to this issue.

Looking at your code it looks like this is fixed in the 1.1.5 version, but that 1.1.6 reverted to a previous version where the fix was not in place.

Thank you for helping me here. We had to back out v1.1.5 -- the updates were done by a third party who introduced serious regressions, unfortunately. We will try to get to this over the next couple weeks.

Thanks. I'm using a version of the plugin where I made the edits suggested above and it is working well enough for us to continue to use it. I'm not seeing any errors in the logs related to the plugin either. So, maybe this is enough of a fix to at least make the plugin work on php 8. But, like I said - I just hacked at the code until it worked again. I was going to submit a PR with the changes but master is version 1.1.5 and I'm not sure how to pull a copy of 1.1.3 to do that so, we'll limp along as is for the time being.

Appreciate this! We have to update the master to reflect backing out v1.1.4 and v.1.1.5 changes.

If you do, update me here, I'll pull that and make a PR for this fix - maybe it would help.

I found the same issue and solved it by changing this in class-power-bi-php:

		function get_powerbi_access_token() {

			// Nikola: 2023-04-17 This is deprecated in PHP 7 and will fail in PHP 8: 
			// $returnObject = Power_Bi_Oauth::get_token();
			// This will work instead:
			$returnObject = Power_Bi_Oauth::get_instance()->get_token();
			return $returnObject['access_token'];
		}

I will follow this issue as well to stay notified about when this is fixed.

@nikolaschou I like your solution better than mine. I'll change my edit when I redeploy next week for our site. I do hope the actual plugin gets updated soon.

The solution provided here by @nikolaschou seems like a simple solution to this issue. Any chance you might be able to release that as a small update to the official plugin?

Just closing the loop here. We incorporated the wonderful edit from @nikolaschou and pushed an update on WordPress. We also rolled back changes on GitHub last year that unfortunately introduced a number of regressions. We'll try to reincorporate some of those features this year.