# Changing output of print_r() and var_dump()

- Thread: https://externals.io/message/16286
- Original archive: https://news-web.php.net/php.internals/16286
- Started by Marcus Boerger on 2005-05-21T14:33:44+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #16286 — Marcus Boerger — 2005-05-21T14:33:44+00:00

URL: https://externals.io/message/16286#16286

Hello internals,

  i want to chnage the output of `print_r()` and `var_dump()` so that it
shows the class a private property was declared in. The problem is that at
the moment both only state that the property is private so that you cannot
see which class level it belongs to and if there is any derived class with
a private property having the same name you cannot distinguish them.

See patch attached.

Here is the output of the unpatched version:
php > class T {
php { protected $pro = 1;
php { private $pri = 2;
php { public $pub = 3;
php { }
ew T;
php > $o = new T;
php > print_r($o);
T Object
(
    [pro:protected] => 1
    [pri:private] => 2
    [pub] => 3
)
php > class TT extends T {
php { private $pri = 4;
php { }
php > $oo = new TT;
php > print_r($oo);
TT Object
(
    [pri:private] => 4
    [pro:protected] => 1
    [pri:private] => 2
    [pub] => 3
)
php >

Here is the output of the patched version:
php > class T {
php { protected $pro = 1;
php { private $pri = 2;
php { public $pub = 3;
php { }
php > $o = new T;
php > print_r($o);
T Object
(
    [pro:protected] => 1
    [pri:private:T] => 2
    [pub] => 3
)
php > class TT extends T {
php { private $pri = 4;
php { }
php > $oo = new TT;
php > print_r($oo);
TT Object
(
    [pri:private:TT] => 4
    [pro:protected] => 1
    [pri:private:T] => 2
    [pub] => 3
)

If nobody objects i'll apply this tomorrow.

-- 
Best regards,
 Marcus                          mailto:mail@marcus-boerger.de

---

## #16287 — Wez Furlong — 2005-05-22T12:21:38+00:00

URL: https://externals.io/message/16286#16287 · In reply to: #16286

If we're going to change it, can we make it "visibility:class:name"
instead, as this seems more intuitive and readable.

eg:  private:TT:pri

--Wez.


> Hello internals,
> 
>   i want to chnage the output of `print_r()` and `var_dump()` so that it
> shows the class a private property was declared in. The problem is that at
> the moment both only state that the property is private so that you cannot
> see which class level it belongs to and if there is any derived class with
> a private property having the same name you cannot distinguish them.
> 
> See patch attached.
> 
> Here is the output of the unpatched version:
> php > class T {
> php { protected $pro = 1;
> php { private $pri = 2;
> php { public $pub = 3;
> php { }
> ew T;
> php > $o = new T;
> php > print_r($o);
> T Object
> (
>     [pro:protected] => 1
>     [pri:private] => 2
>     [pub] => 3
> )
> php > class TT extends T {
> php { private $pri = 4;
> php { }
> php > $oo = new TT;
> php > print_r($oo);
> TT Object
> (
>     [pri:private] => 4
>     [pro:protected] => 1
>     [pri:private] => 2
>     [pub] => 3
> )
> php >
> 
> Here is the output of the patched version:
> php > class T {
> php { protected $pro = 1;
> php { private $pri = 2;
> php { public $pub = 3;
> php { }
> php > $o = new T;
> php > print_r($o);
> T Object
> (
>     [pro:protected] => 1
>     [pri:private:T] => 2
>     [pub] => 3
> )
> php > class TT extends T {
> php { private $pri = 4;
> php { }
> php > $oo = new TT;
> php > print_r($oo);
> TT Object
> (
>     [pri:private:TT] => 4
>     [pro:protected] => 1
>     [pri:private:T] => 2
>     [pub] => 3
> )
> 
> If nobody objects i'll apply this tomorrow.
> 
> --
> Best regards,
>  Marcus                          mailto:mail@marcus-boerger.de
