Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DomCrawler] Added argument$default to methodCrawler::attr()#51368

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:6.4fromRastishka:6.4
Aug 16, 2023

Conversation

@Rastishka
Copy link
Contributor

QA
Branch?6.4
Bug fix?no
New feature?yes
Deprecations?no
Ticketsno
LicenseMIT
Doc PRsymfony/symfony-docs#...

Added argument$default to method->attr() like->text() and->html() have.

GromNaN and Rastishka reacted with thumbs up emoji
@nicolas-grekas
Copy link
Member

Do we really need this? My feeling is that we now have the?? operator and it's nicer to use.

antonkomarev reacted with heart emoji

@antonkomarev
Copy link

antonkomarev commentedAug 12, 2023
edited
Loading

I'd prefer to use native??. It feels more obvious about the result.

@Rastishka
Copy link
ContributorAuthor

Do we really need this? My feeling is that we now have the?? operator and it's nicer to use.

Yes we need, because setting default value also prevents throwing exception when node does not exist (methods text() and html() act similar).

So this code:

try {    $value = $dom->filter('a.someclass')->attr('href');} catch (\InvalidArgumentException $e) {    $value = '';}

can be simplifies to
$value = $dom->filter('a.someclass')->attr('href', '');

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the explanation. Works for me.

@nicolas-grekas
Copy link
Member

Please also update the UPGRADE-6.4.md file, and please rebase to get rid of merge commits (PRs shouldn't contain any).

@nicolas-grekasnicolas-grekas changed the titleAdded argument$default to method->attr() like->text() and->html() have.Added argument$default to methodCrawler::attr()Aug 16, 2023
@carsonbotcarsonbot changed the titleAdded argument$default to methodCrawler::attr()[DomCrawler] Added argument$default to methodCrawler::attr()Aug 16, 2023
@nicolas-grekas
Copy link
Member

Thank you@Rastishka.

Rastishka reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

4 participants

@Rastishka@nicolas-grekas@antonkomarev@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp