Thoughts on php’s print_r

Posted: March 25th, 2010 | Author: | Filed under: PHP | Comments Off on Thoughts on php’s print_r

Just a quick quick question: Why does php’s print_r function, which is pretty usefull to all, feature a $return (optional) argument? Not a question about it’s usefulness, but rather the choice to include this into the print_r. I would prefer to see an sprint_r variant behaving like

function sprint_r($sIn){
     return print_r($sIn, true);

to conform to choices made for (s)printf. While on the subject, why not include a fprint_r as well (useful perhaps for logging):

function fprint_r($oFP, $sIn){
     return fwrite($oFP, sprint_r($sIn));

and perhaps a vprint_r to complete the symmetry, though I have no clue as to what it should do :).

Comments are closed.