Bug #76434 [Csd->Nab]: implode sometimes ignores one array item
Edit report at https://bugs.php.net/bug.php?id=76434&edit=1
ID: 76434
Updated by: requinix@php.net
Reported by: ceeckels at mac dot com
Summary: implode sometimes ignores one array item
-Status: Closed
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: MacOS, FreeBSD
PHP Version: 7.1.18
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2018-06-10 10:52:48] ceeckels at mac dot com
The problem is not PHP-related. It is a problem wit Apple's Terminal.app. The string output by
the bash command
echo -e '12345678\t12345678\t12345678\t3\t4\t5\t6\t7\t8'
depends on the Terminal windows's width.
So I owe an apology to PHP's implode function.
Thanks to everybody. Bug should be closed.
------------------------------------------------------------------------
[2018-06-08 23:53:53] danack@php.net
Also, this has a very small chance of being a weird interaction between your terminal and the bytes.
Please could you run this to see what implode is actually doing.
function getRawCharacters($result) {
$resultInHex = unpack('H*', $result);
$resultInHex = $resultInHex[1];
$resultSeparated = implode(', ', str_split($resultInHex, 2));
return $resultSeparated;
}
$ar = [12345678, 12345678, 12345678, 3, 4, 5, 6, 7, 8];
$string = implode(chr(9), $ar);
echo getRawCharacters($string) . PHP_EOL;
------------------------------------------------------------------------
[2018-06-08 23:35:13] danack@php.net
I can't reproduce https://3v4l.org/kEBSX and it sounds
weird.
Please can you test again with opcache disabled, if it's currently enabled.
Also please try with all other extensions disabled.
------------------------------------------------------------------------
[2018-06-08 23:12:01] ceeckels at mac dot com
Description:
------------
No comment; just run the test script and notice that the array item 7 is missing in the result
string
Test script:
---------------
<?php
$ar = [12345678, 12345678, 12345678, 3, 4, 5, 6, 7, 8];
echo implode(chr(9), $ar), PHP_EOL;
?>
Expected result:
----------------
12345678 12345678 12345678 3 4 5 6 7 8
Actual result:
--------------
12345678 12345678 12345678 3 4 5 6 8
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76434&edit=1
Thread (5 messages)