-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DomCrawler] Callable type hint #14293
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
Conversation
3.0.0 | ||
----- | ||
|
||
* The first argument of `Crawler::each()` and `Crawler::reduce()` are type hinted with `callback` instead of `Closure`. |
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.
callable
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.
Fixed
{ | ||
$nodes = array(); | ||
foreach ($this as $i => $node) { | ||
if (false !== $closure(new static($node, $this->uri, $this->baseHref), $i)) { | ||
if (false !== $fn(new static($node, $this->uri, $this->baseHref), $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 does not work for all types of callables. There is still 1 type of callable passing the typehint but failing for the direct call
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.
have you tested the 5 examples in your PR description btw ?
After review it again with some tests i can see that only the object method callback type works, so i will update the PR description. |
All callback types that pass the Should the typehints be changed from |
@mpajunen AFAIK, we don't have lots of Closure typehints. We support callables almost everywhere (and we should probably convert the is_callable checks to typehints indeed). And some places where we check for Closure explicitly are intended (in the OptionsResolver for instance). |
Replaced by #14330 |
As of PHP 5.4 exists the
callable
type hint. Example: