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

[ExpressionLanguage] throws an exception on calling uncallable method#24041

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
fabpot merged 1 commit intosymfony:2.7fromfmata:expressionlanguage_iscallable
Sep 5, 2017
Merged

[ExpressionLanguage] throws an exception on calling uncallable method#24041

fabpot merged 1 commit intosymfony:2.7fromfmata:expressionlanguage_iscallable
Sep 5, 2017

Conversation

@fmata
Copy link
Contributor

@fmatafmata commentedAug 30, 2017
edited
Loading

QA
Branch?2.7
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRn/a

When we evaluate an expression, if a callable is incorrect (not exists or not accessible) a warning is printed.
This PR handles this case and throws a \RuntimeException whenis_callable() returnsfalse :

$el =newExpressionLanguage();$el->evaluate('foo.myfunction()',array('foo' =>new \stdClass()));

Before:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'stdClass' does not have a method 'myfunction' in /home/.../src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php on line 84

After:
Fatal error: Uncaught RuntimeException: Unable to call method "myfunction" of object "stdClass". in /home/.../src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php:81

peshkopy, apetitpa, and Koc reacted with thumbs up emoji
if (!is_object($obj)) {
thrownew \RuntimeException('Unable to get a property on a non-object.');
}
if (($toCall =array($obj,$this->nodes['attribute']->attributes['value'])) && !is_callable($toCall)) {

Choose a reason for hiding this comment

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

if (!is_callable($toCall = array($obj, $this->nodes['attribute']->attributes['value']))) {

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

$registerCallback($el);
}

/**

Choose a reason for hiding this comment

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

please add also an@expectedExceptionMessage annotation

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I did not add before to be consistent with the codebase in this component. I use@expectedExceptionMessageRegExp instead :)

@fabpot
Copy link
Member

Thank you@fmata.

@fabpotfabpot merged commitc8b65ae intosymfony:2.7Sep 5, 2017
fabpot added a commit that referenced this pull requestSep 5, 2017
…able method (fmata)This PR was merged into the 2.7 branch.Discussion----------[ExpressionLanguage] throws an exception on calling uncallable method| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | n/aWhen we evaluate an expression, if a callable is incorrect (not exists or not accessible) a warning is printed.This PR handles this case and throws a \RuntimeException when `is_callable()` returns `false` :```php$el = new ExpressionLanguage();$el->evaluate('foo.myfunction()', array('foo' => new \stdClass()));```**Before:**`Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'stdClass' does not have a method 'myfunction' in /home/.../src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php on line 84`**After:**`Fatal error: Uncaught RuntimeException: Unable to call method "myfunction" of object "stdClass". in /home/.../src/Symfony/Component/ExpressionLanguage/Node/GetAttrNode.php:81`Commits-------c8b65ae [ExpressionLanguage] throws an exception on calling uncallable method
@fabpotfabpot mentioned this pull requestSep 11, 2017
This was referencedOct 5, 2017
@fmatafmata deleted the expressionlanguage_iscallable branchMarch 9, 2018 19:15
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@chalasrchalasrchalasr approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

2.7

Development

Successfully merging this pull request may close these issues.

5 participants

@fmata@fabpot@nicolas-grekas@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp