You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason this happens can be found inside the PhpView class
The toString method needs to have some form of error handling that resets the buffered content. If not PHP will automatically clear and print the output when an exception occurs and the script shuts down.
publicfunctiontoString() {
if ( empty( $this->getName() ) ) {
thrownewViewException( 'View must have a name.' );
}
if ( empty( $this->getFilepath() ) ) {
thrownewViewException( 'View must have a filepath.' );
}
$this->engine->pushLayoutContent( $this );
if ( $this->getLayout() !== null ) {
// ERROR HAPPENS HEREreturn$this->getLayout()->toString();
}
return$this->engine->getLayoutContent();
}
A possible fix would be changing the relevant part to something like this:
publicfunctiontoString() {
// left out for brevityob_start();
try {
if ( $this->getLayout() !== null ) {
// ERROR HAPPENS HEREreturn$this->getLayout()->toString();
}
$this->engine->getLayoutContent();
}
catch ( Throwbable$e ) {
ob_end_clean();
thrownewViewException();
}
returnob_get_clean();
}
The text was updated successfully, but these errors were encountered:
Version
Please add the exact versions used for each of the following:
Expected behavior
When an exception occurs inside rendering a view, all output buffers are cleared, and an exception is thrown to render an error page appropriately.
Actual behaviour
Right now, any error that happens inside view rendering will cause any HTML before the error to be printed to the client.
Steps to reproduce (in case of a bug)
Turn on
WP_DEBUG
(optional)Visit
yoursite.com/foo
See
Foobar
in the error page html.Comments
The reason this happens can be found inside the
PhpView
classThe
toString
method needs to have some form of error handling that resets the buffered content. If not PHP will automatically clear and print the output when an exception occurs and the script shuts down.A possible fix would be changing the relevant part to something like this:
The text was updated successfully, but these errors were encountered: