php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77655 Long String in Return Value is Empty
Submitted: 2019-02-22 09:52 UTC Modified: 2019-03-03 04:22 UTC
From: marc dot ruef at computec dot ch Assigned:
Status: No Feedback Package: Strings related
PHP Version: 7.3.2 OS: Linux Kernel 3.10.0-862.14.4.el7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marc dot ruef at computec dot ch
New email:
PHP Version: OS:

 

 [2019-02-22 09:52 UTC] marc dot ruef at computec dot ch
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;


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-22 09:56 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2019-02-22 09:56 UTC] nikic@php.net
Can you please provide a full reproduction script including the $result array that you're using? (Can just be some generated dummy data that produces this issue).
 [2019-03-03 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 12:01:30 2024 UTC