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
3.0 Cell::__toString() must not throw an exception #3664
Comments
I don't think swallowing errors is a good idea. It might be better to return the exception message instead. |
|
Agreed, I think there are a few problems here:
Does the above sound reasonable? |
I consider cells something similar to elements with its own logic (witch by the way are really great). I guess nonexistent cell methods should be threaten like non existend element files - people get used to that IMO |
I would prefer that we throw an exception instead of pretending the file doesn't exist. In fact, I'd say not throwing an exception for a non-existent element is a bug, given that this is certainly not what the user wanted. |
Missing elements do trigger errors. I'll update element() to use an exception along with these changes. |
Use reflection to capture missing cell methods and raise proper errors on them. Refs #3664
Because __toString methods cannot emit exceptions, we render a string error. This gives the developer some feedback about what is broken. Refs #3664
Closing as #3676 is now open. |
Use reflection to capture missing cell methods and raise proper errors on them. Refs #3664
Because __toString methods cannot emit exceptions, we render a string error. This gives the developer some feedback about what is broken. Refs #3664
What i did:
in the console: /cake bake cell Sidebar
in my layout cell('Sidebar::nonexistentmethod');?>
What happened:
Warning (2): call_user_func_array() expects parameter 1 to be a valid callback, class 'App\View\Cell\SidebarCell' does not have a method 'categories' [ROOT\vendor\cakephp\cakephp\src\View\CellTrait.php, line 83]
and then:
Fatal Error
Error: Method App\View\Cell\SidebarCell::__toString() must not throw an exception
I think a fatal here is not intentional and dont really tell whats going on, warning should do the job. Php.net says You cannot throw an exception from within a __toString() method. Doing so will result in a fatal error.
http://www.php.net/manual/en/language.oop5.magic.php#object.tostring
Solution:
In View/Cell.php
public function __toString() {
try{
return $this->render();
catch(Exception $ex){
return '';
}
}
The text was updated successfully, but these errors were encountered: