-
Notifications
You must be signed in to change notification settings - Fork 152
adds isStatic and isNotStatic #310
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
adds isStatic and isNotStatic #310
Conversation
what would be a real life use case for this exactly? What property of a static function can break 3rd party code versus non-static function that simply does not use |
|
So if you're writing an API that accepts a Closure but contextually binds it later on it will stop the code from working. $obj = new stdClass();
$function = static function () {
return 'foo';
};
$function->bindTo($obj);This would then throw an exception like 'Cannot bind an instance to a static closure'. A good example of where I've seen this happen is with Pest where you provide closures where the Closure is then bound to a different object. There's probably less of a need for |
|
@peterfox sorry for the delay here. If you'd still like to see this merged, please rebase to latest |
# Conflicts: # src/Assert.php
|
@shadowhand thanks, having a look but might take a day or two to get myself back up to speed. |
81a2673 to
340e948
Compare
|
Tests are failing...
|
src/Assert.php
Outdated
| /** | ||
| * @param Closure $closure | ||
| * @param string $message | ||
| * @throws InvalidArgumentException|ReflectionException |
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.
What scenario would cause ReflectionException to be thrown?
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.
Actually shouldn't happen. It would only occur if a string was passed to the ReflectionFunction constructor but that shouldn't happen as the assertions only accept callables.
shadowhand
left a comment
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.
@peterfox changes look good. Assuming tests pass, I'll merge and clean up.
Changes
isStaticandisNotStatic.Why
This can be useful in some libraries where you want to make sure that the end user hasn't provided a static function as an argument.