php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53766 make RecursiveTreeIterator maintain prefix when values contain \n
Submitted: 2011-01-17 12:47 UTC Modified: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: henry at henrysmith dot org Assigned:
Status: Open Package: SPL related
PHP Version: 5.3.5 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-01-17 12:47 UTC] henry at henrysmith dot org
Description:
------------
When printing an array using RecursiveTreeIterator, it'd be nice if it could handle new lines in the printed values without losing the tree prefix before every line after the first.

Perhaps it'd make a good optional flag? Or does this option already exist but is undocumented?

Test script:
---------------
$array = array(
        'a' => array(
                'a1' => array(1, "lol\nlol\nlol", 3),
                'a2' => array(3, 4, 5),
        ),
        'b' => array(
                'b1' => array(6, 7, 8),
                'b2' => array(9),
        ),
);

function print_ansi($array)
{
        $rai = new RecursiveArrayIterator($array);
        $rti = new RecursiveTreeIterator($rai);

        $rti->setPrefixPart(0, '');
        $rti->setPrefixPart(1, "\033(0\170\033(B   ");
        $rti->setPrefixPart(2, "    ");
        $rti->setPrefixPart(3, "\033(0\164\161\161\033(B ");
        $rti->setPrefixPart(4, "\033(0\155\161\161\033(B ");
        $rti->setPrefixPart(5, "\033(B");

        foreach($rti as $value) {
                echo $value, PHP_EOL;
        }
}

print_ansi($array);

Expected result:
----------------
├── Array
│   ├── Array
│   │   ├── 1
│   │   ├── lol
|   |   |   lol
|   |   |   lol
│   │   └── 3
│   └── Array
│       ├── 3
│       ├── 4
│       └── 5
└── Array
    ├── Array
    │   ├── 6
    │   ├── 7
    │   └── 8
    └── Array
        └── 9

Actual result:
--------------
├── Array
│   ├── Array
│   │   ├── 1
│   │   ├── lol
lol
lol
│   │   └── 3
│   └── Array
│       ├── 3
│       ├── 4
│       └── 5
└── Array
    ├── Array
    │   ├── 6
    │   ├── 7
    │   └── 8
    └── Array
        └── 9

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC