Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Can I count on the print_r function to output info in the same format

I did a print_r on an array and got something like this:

    [status] => 0
    [email] =>
    [firstname] => bob
    [lastname] => smith
    [id] => 148
    [access] => 2040ad981d3302d63564b990fea38268

I want to make sure that doesn't change in PHP 6 or 7.

Re: print_r

On 11/3/2011 11:24 AM, bob wrote:
Quoted text here. Click to load it

There is no guarantee the output format will remain the same in any version.

But does it make a difference?  No.  It's meant to be a debug aid, not a
way of passing information to another program or similar.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: print_r

On Thu, 03 Nov 2011 08:24:01 -0700, bob wrote:

Quoted text here. Click to load it

No, if you want a consistently formatted text representation of an array
to, for example, transfer data between applications, you might be better
either using the json encoding, or the built in serialisation, or writing
your own array to text function.

Obviously, whichever one you use, you'll need matching routines at the
the other end. json encoding is fairly well supported with code or
libraries available for many different languages at

Although there's nothing there for ada, fortran or pascal yet :(


Denis McMahon

Re: print_r

El 03/11/2011 16:24, bob escribió/wrote:
Quoted text here. Click to load it

I wouldn't count on that. You probably have a better chance with
var_dump() which (apart from being more accurate) is used in unit
testing in the PHP code itself. E.g.:

I mean, they can change it whenever they want, but they'll break their
own tests.

(I hope you're are planning to write unit tests or something like that;
there are betters choices to store or transmit information.)

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Site Timeline