Freemius / freemius-php-sdk

https://freemius.com
22 stars 13 forks source link

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

Open daigo75 opened 2 years ago

daigo75 commented 2 years ago

🐞 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: (*)