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

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

Merged
merged 1 commit into from Sep 5, 2017

Conversation

Projects
None yet
5 participants
@fmata
Contributor

fmata commented Aug 30, 2017

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/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 when is_callable() returns false :

$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

@@ -164,6 +164,15 @@ public function testRegisterAfterEval($registerCallback)
}
/**
* @expectedException \RuntimeException

This comment has been minimized.

@nicolas-grekas

nicolas-grekas Aug 31, 2017

Member

please add also an @expectedExceptionMessage annotation

@nicolas-grekas

nicolas-grekas Aug 31, 2017

Member

please add also an @expectedExceptionMessage annotation

This comment has been minimized.

@fmata

fmata Aug 31, 2017

Contributor

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

@fmata

fmata Aug 31, 2017

Contributor

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

@chalasr

chalasr approved these changes Sep 4, 2017

@fabpot

fabpot approved these changes Sep 5, 2017

@fabpot

This comment has been minimized.

Show comment
Hide comment
@fabpot

fabpot Sep 5, 2017

Member

Thank you @fmata.

Member

fabpot commented Sep 5, 2017

Thank you @fmata.

@fabpot fabpot merged commit c8b65ae into symfony:2.7 Sep 5, 2017

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Sep 5, 2017

bug #24041 [ExpressionLanguage] throws an exception on calling uncall…
…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/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 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

@fabpot fabpot referenced this pull request Sep 11, 2017

Merged

Release v3.3.9 #24156

This was referenced Oct 5, 2017

@fmata fmata deleted the fmata:expressionlanguage_iscallable branch Mar 9, 2018

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