-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.0] Fix a bug in Registry.php #49
Conversation
src/Registry.php
Outdated
@@ -508,11 +508,13 @@ public function set($path, $value, $separator = null) | |||
switch (true) | |||
{ | |||
case (is_object($node)): | |||
$result = $node->{$nodes[$i]} = $value; | |||
$result = $node->{$nodes[$i]}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be $result = $node->{$nodes[$i]} ?? null;
(similar for the array case), as is it's causing unit test failures because of undefined properties.
src/Registry.php
Outdated
@@ -508,11 +508,13 @@ public function set($path, $value, $separator = null) | |||
switch (true) | |||
{ | |||
case (is_object($node)): | |||
$result = $node->{$nodes[$i]} = $value; | |||
$result = $node->{$nodes[$i]} ?? $value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the intent is to return the previously set value, I'd suggest returning null would be the correct behavior. Otherwise now you're in a mixed case where if it wasn't previously set you're getting the newly set value and if it was previously set you're getting the old value and that API inconsistency isn't necessarily a good thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. But seems that $result = $node->{$nodes[$i]} ?? null cannot pass unit test...strange
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is why I said this had to be fixed on the 2.0 branch only. Because the current code behavior, and inherently the tests, all return the newly set value and if the intent is to change it to follow the docs and return the old value, the tests need updating to account for that change in behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thank you for your patience.
Should we correct the code and unit tests here or change the document instead? |
Personally, I would suggest to change it.
So our API design favors setters returning the previous values, with that said though there are some places where our setters have no return as well (i.e. our @wilsonge thoughts? |
# Conflicts: # src/Registry.php
The tests where looking for a different behaviour than documented. Setting a value in a Registry should actually return the previous value (or null, if set for the first time).
Thank you! |
In class Registry, function set() is supposed to return the old value if exists, according to the comment.
But actually return the newly set value, since assignment is right-associated.