php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42878 Feature proposal for print_r (for all PHP versions!)
Submitted: 2007-10-06 13:37 UTC Modified: 2007-10-06 16:15 UTC
From: rc at opelgt dot org Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.4 OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rc at opelgt dot org
New email:
PHP Version: OS:

 

 [2007-10-06 13:37 UTC] rc at opelgt dot org
Description:
------------
My reason for writing was to make PHP a bit more comfortable.
I dont want to spam. I have tried to email you besides this bug 
reporting system at johannes@php.net without success.

You are doing your job for the same reason I do report this: idealism.

I first didnt understood what you meant with "variable container" 
cause I have studied physics, not informatics.

Now I see the problematic that only the value and not the name is 
given the function print_r.

My native language isnt english but german.

I dont know the internal means of PHP and if a method ".name" exists.
I only wanted to say it would be nice.

I think that is the critical point very often: first to say "Yes I 
understand you, what you want is a good idea, unfortunately its not so 
easy to realize."

<?php
function print_rc($variable_name)
 {
  global ${$variable_name};
  echo "Array \$$variable_name\n {\n";
  foreach(${$variable_name} as $key => $val) echo "  [$key] => 
$val\n";
  echo " }\n";
 }
$arr = array(1,2,3);
print_rc('arr');
?>

This is doing what I want. And the problem is instead giving the value 
to the function (print_r) here (print_rc) the name is given.

So my wish is incompatible with the current implementation of PHPs 
print_r.

Its a pity.

Its my part to give this suggestion and its your part to decide 
whether its a nice thing and when "yes" how that can be implemented.

You can see now that with an optional second parameter in print_r 
(interpreting the given variable as a name) or an additional new php-
function print_rc my wish is possible. With the recent implementation 
of print_r it may not be possible.

I dont want to waste my time describing the current state. I want to 
give a suggestion for the future. Realisation isnt impossible.

R?diger


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-06 16:15 UTC] johannes@php.net
Your code makes the assumption that one wants to print_r a variable from the globals scope. print_r'ing a variable from a function won't work:

<?php
$a = "grhgchlkmehvzfvehe";

function foobar() {
    $a = array(1, 2, 5, 7, 8);
    print_rc("a");
}

foobar();
?>

If such a limitation is acceptable for you: Put that to your default library and use it, for a regular, internal, PHP function such a limitation isn't acceptable.

I hope we can end this now.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Aug 15 18:00:02 2025 UTC