-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Clarify exception message in Twig_Template::getAttribute #2009
Conversation
Sounds like a good idea to me. The C extension must also be updated. |
16abb3a
to
a84cbd9
Compare
@fabpot Thank's for your quick reply. I'm trying to update the C extension, but I'm facing difficulties to use Is there something specific to do in order to use this php function ? I tried to call |
|
@@ -581,7 +581,7 @@ protected function getAttribute($object, $item, array $arguments = array(), $typ | |||
return; | |||
} | |||
|
|||
throw new Twig_Error_Runtime(sprintf('Method "%s" for object "%s" does not exist', $item, get_class($object)), -1, $this->getTemplateName()); | |||
throw new Twig_Error_Runtime(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%2$s()"/"is%2$s()" or "__call()" exist and have public access in class "%3$s"', $item, ucfirst($item), get_class($object)), -1, $this->getTemplateName()); |
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.
just use 'get'.$item
as used when calling the method. PHP method names are case insensitive anyway
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 will help you for the C extension btw, as you won't need to implement ucfirst anymore
fa2b5a9
to
9005969
Compare
Add missing parenthesis Adapt twig.c extension Update the C extension Use php_ucfirst instead of ucfirst Try to implement a TWIG_UCFIRST in C extension Last try ucfirst Rollback twig.c extension Remove useless ucfirst + update twig.c extension Fix mis-escaped char Repeat argument item for sprintf (first try doesnt work) Remove unexpected breakline in code
👍 |
2 similar comments
👍 |
👍 |
Thank you @chalasr. |
…e (chalasr) This PR was merged into the 1.x branch. Discussion ---------- Clarify exception message in Twig_Template::getAttribute When a non existing property/method is called for an object, the exception message is: > Method "property()" for object "[class]" does not exist in [template]" But in fact the `Twig_Template::getAttribute()` method check for (at least) 3 more methods (`isProperty()`, `getProperty()` and `__call__()`). It could be more adapted and easier to be debugged if the message would be: > Neither the property "property" nor one of the methods "property]()", "getProperty()"/"isPropertyt()" or "__call()" exist and have public access in class "[class]" in [template] This message is mostly inspired from the one used in the PropertyAccess component. BTW I think that it would be great to replace all the checks listed above by a `PropertyAccessor::isReadable([property])`. I can work on a PR if it's not overkill. Commits ------- d455b52 Clarify exception message in Twig_Template::getAttribute
When a non existing property/method is called for an object, the exception message is:
But in fact the
Twig_Template::getAttribute()
method check for (at least) 3 more methods (isProperty()
,getProperty()
and__call__()
).It could be more adapted and easier to be debugged if the message would be:
This message is mostly inspired from the one used in the PropertyAccess component.
BTW I think that it would be great to replace all the checks listed above by a
PropertyAccessor::isReadable([property])
.I can work on a PR if it's not overkill.