Repository navigation
Fix PHP 8 fatal/warning on first opt-in without paid plans - #888
Open
Tobias-Conrad wants to merge 1 commit into
Open
Tobias-Conrad wants to merge 1 commit into
Tobias-Conrad wants to merge 1 commit into
Conversation
On a fresh first opt-in, _plans defaults to false and _set_account() skips the assignment when no plan list is passed. Two spots then touched it as if it were an array/object: - _store_plans(): count( $this->_plans ) on false -> fatal TypeError (PHP 8). - FS_Site::__construct(): read $site->plan_id which the install payload can omit -> 'Undefined property: stdClass::$plan_id' warning (PHP 8). Both are now guarded, matching the existing '! is_array( $this->_plans )' convention used elsewhere in the class. Refs Freemius#879
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
On a fresh first opt-in of a product/store, the SDK can raise two PHP 8 diagnostics before the account carries any plan list (see #879, reproduced on SDK 2.13.1/2.13.4 and current
develop):Fatal error —
_store_plans()callscount( $this->_plans )while$this->_plansis still its defaultfalse:Warning —
FS_Site::__construct()reads$site->plan_id, which the install payload can omit:Root cause
$this->_plansdefaults tofalse(declarationprivate $_plans = false;)._set_account()only assigns it when a plan list is passed:On a first opt-in without paid plans,
$plansstaysfalse, and_store_plans()is still reached via_store_account().The change (minimal, two spots)
_store_plans(): encrypt an empty list when_plansis not an array, instead of callingcount()onfalse.FS_Site::__construct(): readplan_idviaisset()and default tonull, matching how the property is handled elsewhere.Both use the exact convention already present in the class (
! is_array( $this->_plans ), see_get_plan_by_id()/get_plan_by_name()), so this is consistent with the existing code style rather than a new pattern.Verification
php -lclean on both changed files._plansis a real array.No other code paths were touched:
is_plan()/is_trial_plan()etc. are only reached onceis_registered()is true, at which point_plansis already an array — so they are not on the reported crash path.Fixes #879.