Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: Undefined property: Freemius_Api::$_sandbox #16

Open
daigo75 opened this issue Dec 15, 2021 · 0 comments
Open

Notice: Undefined property: Freemius_Api::$_sandbox #16

daigo75 opened this issue Dec 15, 2021 · 0 comments

Comments

@daigo75
Copy link

daigo75 commented Dec 15, 2021

🐞 bug report

Behavior:
I tried some scheduled tasks via wp-cli, and the following notice appeared
Notice: Undefined property: Freemius_Api::$_sandbox in /path/to/freemius/php-sdk/freemius/Freemius.php on line 69

Affected line
https://github.com/Freemius/freemius-php-sdk/blob/master/freemius/Freemius.php#L69

Cause
The affected line contains the following code:
return ($this->_sandbox ? FS_API__SANDBOX_ADDRESS : FS_API__ADDRESS) . $pCanonizedPath;

Property $this->_sandbox is not declared as part of the Freemius_Api class, it's a dynamic property. Due to that, it doesn't exist until something sets its value:

// This throws a notice
echo $this->_sandbox; 
// This creates and initialises the property
$this->_sandbox = 'value';
// This works as expected
echo $this->_sandbox;

Solution
Declaring the Freemius_Api::$_sandbox property will fix the issue. This will become necessary anyway, because dynamic properties will be deprecated in PHP 8.2 and completely removed in PHP 9.0
lob/84a9be4717effd7697a217e0d931f48ae0d2ecc6/config.php#L160

Versions: (*)

  • Freemius PHP SDK Version: dev-master, from Packagist.
  • WordPress Version: 5.8
  • PHP Version: 7.4.x or newer.
daigo75 pushed a commit to aelia-co/freemius-php-sdk that referenced this issue Aug 10, 2022
* Added check for `FS_SDK__USER_AGENT`.
* Added check for `FS_API__PROTOCOL`.
* Added check for `Freemius_Api::$_sandbox`. Fixes Freemius#16.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant