Bug #77655 [NEW]: Long String in Return Value is Empty
| From: | marc dot ruef at computec dot ch | Date: | Fri, 22 Feb 2019 09:52:11 +0000 |
| Subject: | Bug #77655 [NEW]: Long String in Return Value is Empty | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219699@lists.php.net to get a copy of this message | ||
From: marc dot ruef at computec dot ch
Operating system: Linux Kernel 3.10.0-862.14.4.el7
PHP version: 7.3.2
Package: Strings related
Bug Type: Bug
Bug description:Long String in Return Value is Empty
Description:
------------
I am having a for loop which is iterating through a large array $result.
Every array item $row is used to generate a new line of string $line.
This string is concatenated into $str. To preserve memory, I am using
unset($result[$i]) to clear every array item that has been processed in
the original array.
This (more or less exotic piece of code) works unless the string exceeds
a length of 999'775 characters. In this case the return value is just
empty. This is highly irritating because:
1. The calculation effort (in this example do_something()) is not a
problem. By using
echo count($result).' - '.strlen($str)."\n" I can
see that the loop finishes properly. There is no web server or php error
shown.
2. The memory_limit is also not a problem. I am working with more data
on other parts of the application.
It appears that the problem lies in return $str itself. If I am using
return substr($str, 0, 980000) then it just works fine.
I can't put those exceeding return value strings into another string
variable. But I am able to do a strlen() to get a proper result
(1310307). But I can't use them properly as a string. Using an `echo
$str` in the function works properly. But return doesn't.
Test script:
---------------
function what_is_going_on($result){
$resultcount = count($result);
for($i=0; $i<$resultcount; ++$i){
$row = $result[$i];
$line = do_something($row);
$str.= $line;
unset($result[$i]);
}
return $str;
}
$output = what_is_going_on($result);
echo $output;
--
Edit bug report at https://bugs.php.net/bug.php?id=77655&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77655&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77655&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77655&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77655&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77655&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77655&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77655&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77655&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77655&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77655&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77655&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77655&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77655&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77655&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77655&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77655&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77655&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77655&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77655&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77655&r=mysqlcfg