Fixed Template->render() exception handling #78
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Template->render()
callsob_get_clean()
to get the result of rendering the template. According to the PHP manual page for this function, this is what it does, emphasis mine:After this function is called, another block is executed to render the layout. Within this block, it's possible for a
LogicException
to be thrown if, for example, the layout template cannot be found. If this happens, there is acatch
block to handle it.There are two problems with this
catch
block:ob_get_clean()
deleted the output buffer, the call toob_end_clean()
in thecatch
block has no buffer to delete and thus causes a notice to be emitted: "failed to delete buffer. No buffer to delete."LogicException
instance being re-thrown, a new one is being instantiated with the message of the original, causing the trace information associated with the original to be lost. This makes debugging difficult.This PR applies these corrections:
ob_end_clean()
call in aob_get_length()
check so that it is only called if needed, avoiding the previously emitted notice.LogicException
instance so that the original trace information is preserved.