Skip to content

Commit

Permalink
Fail-safe when update class cannot be correctly reconstructed or loaded.
Browse files Browse the repository at this point in the history
Previously, if the wrong base class name was written to the database, attempts to load update information could trigger a warning because there was no class_exists() check in the "updateBaseClass is set" branch. To fix that, I've moved the class_exists() closer to the place where the class name is actually used.

StateStore will still fail to load a stored update if the class name is invalid, but without a PHP warning this time. The invalid stored update information should be overwritten the next time PUC checks for updates.
  • Loading branch information
YahnisElsts committed Jul 28, 2022
1 parent b4c5a82 commit 3347254
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Puc/v4p12/StateStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ protected function load() {
$updateClass = null;
if ( isset($state->updateBaseClass) ) {
$updateClass = $this->getLibPrefix() . $state->updateBaseClass;
} else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
} else if ( isset($state->updateClass) ) {
$updateClass = $state->updateClass;
}

if ( $updateClass !== null ) {
if ( ($updateClass !== null) && class_exists($updateClass) ) {
$this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
}
}
Expand Down

0 comments on commit 3347254

Please sign in to comment.