Skip to content

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

@daigo75

Description

@daigo75

🐞 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions