Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If your page uses print_r, var_export, with the second parameter TRUE; it causes PHP to fail when used within an output buffering callback handler (like boost does).
Cannot use output buffering in output buffering display handlers
PHP Bug
http://marc.info/?l=phpdoc&m=114122422804066&w=2
Alt Function
http://www.php.net/manual/en/function.print-r.php#75872
Comment | File | Size | Author |
---|---|---|---|
#12 | boost-491968.patch | 5.04 KB | mikeytown2 |
Comments
Comment #1
Nigel CunninghamI've just run into this too, after upgrading to 6.x-1.0-beta2.
If there's anything I can do to help, please ask.
Nigel
Comment #2
mikeytown2 CreditAttribution: mikeytown2 commentedSadly this is a PHP bug. Current workaround is to define your own print_r() function. obsafe_print_r() is a ok alt (see links in first post).
Comment #3
Nigel CunninghamSorry for my ignorance, but I'm still relatively new to Drupal and PHP.
Does that mean I have to look through all my modules and replace print_r with obsafe_print_r, and then put the obsafe_print_r function in something like includes/common.inc that's used everywhere?
Regards,
Nigel
Comment #4
mikeytown2 CreditAttribution: mikeytown2 commentedWhat does the error say exactly? Boost even uses a print_r(), so it only happens in special circumstances. Most peoples webpages do not display the raw output from an array.
Comment #5
Nigel CunninghamHmm. I'm not getting it now. I'll report back if I see it again.
Comment #6
ekes CreditAttribution: ekes commentedIt's only an error if you call a buffering function, like print_r($var, true), from within a buffer handling function, like _boost_ob_handler has been defined to be by ob_start('_boost_ob_handler). It's listed in the PHP manual too http://php.net/ob_start :- .
For now I've just changed, in my copy:-
Comment #7
mikeytown2 CreditAttribution: mikeytown2 commentedI should just add obsafe_print_r() to boost; call it boost_print_r(), that way if someone encounters this problem again they can replace print_r without adding in a new function.
Comment #8
Nigel CunninghamThat would be good.
Would boost_print_t still work if the module was (temporarily) disabled?
Comment #9
mikeytown2 CreditAttribution: mikeytown2 commented@NigelCunningham
sadly no, so it's not the best fix.
Comment #10
EvanDonovan CreditAttribution: EvanDonovan commentedYeah, I've been bitten by this one, as well. Looks like the print_r() inside the error_get_last switch statement is causing PHP to choke. If you could add obsafe_print_r()/boost_print_r() that would be great.
Personally, I hate how print_r() interrupts the normal output flow anyway. It's caused me many issues over the past year or so I've programmed in PHP....
Comment #11
EvanDonovan CreditAttribution: EvanDonovan commentedAlso, I noticed that in that very same error-checking switch statement that the E_NOTICE, E_USER_NOTICE, etc. cases are there, but commented out. I remember that in the original issue I posted regarding the error checking that they had been in there so that errors that don't show on the screen don't stop Boost from caching. Is there a reason they were removed?
Comment #12
mikeytown2 CreditAttribution: mikeytown2 commentedPlease test this patch
Comment #13
mikeytown2 CreditAttribution: mikeytown2 commentedcommitted