From:
Operating system: Linux
PHP version: 5.3.5
Package: SPL related
Bug Type: Feature/Change Request
Bug description:make RecursiveTreeIterator maintain prefix when values contain
\n
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
--
Edit bug report at http://bugs.php.net/bug.php?id=53766&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=53766&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=53766&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=53766&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=53766&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=53766&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=53766&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=53766&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=53766&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=53766&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=53766&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=53766&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=53766&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=53766&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=53766&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53766&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53766&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=53766&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=53766&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=53766&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=53766&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=53766&r=mysqlcfg