No longer return $this
on Collection __set()
method
#4458
Merged
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.
Explanation
This PR changes the behavior of
__set()
methods to no longer return$this
. Instead there is no return value.A return type was never formalized in code, but was defined in the DocBlock for
Kirby\Toolkit\Collection
.Although
Kirby\Toolkit\Collection
returns$this
, the subclassKirby\Cms\Collection
does not return anything.kirby/src/Cms/Collection.php
Lines 67 to 78 in e15a4ea
The
Kirby\Cms\Pages
class extendsKirby\Cms\Collection
and does not override__set()
so it therefor also returns nothing.Kirby\Cms\Structure
also extendsKirby\Cms\Collection
. It attempts to return a value in its reimplementation of__set()
, but because it's returningparent::__set()
and theKirby\Cms\Collection
implementation does not return anything, it's effectively returning void.The formal definition of the magic method
__set()
has avoid
return type.Additionally, the PHP Docs also say that a return a type on
__set()
is always ignored. None of their examples return a value either.This PR …
Refactoring
$collection->__set()
methods consistently no longer return the class instance to match PHP's definition for this method.Breaking changes
This is technically a breaking change: the return type is ignored, but only for usage such as
$collection->foo = $example;
. Usage by calling the function literally still would return a value$collection->__set('foo', $example);
.However, the impact of this breaking change should be minimal, considering that
Kirby\Cms\Collection
never returned a value anyways.Ready?
Unit tests for fixed bug/featureFor review team
Add to website docs release checklist (if needed)