Search code examples
phpstringstring-length

PHP string larger than 2048 charatcter turns tu null


In contradiction with the documentation, in the following cycle (I am creating a select) when the variable $retval reaches 2048 characters, it's set to null.

    foreach ($cache_ecmcategories as $category) {
        $retval.= '<option value="'.$category['rowid'].'"';
        if (($isfilter ? $category['label'] : $category['rowid']) == $defaulttx)
            $retval.= ' selected="selected"';
        $retval.= '>'.$category['label'].'</option>'; <== This line generate the problem
    }

Also, change the PHP version from 5.6.25 to 7.0.10, the problem remains the same

What is the cause of this strange behavior?


Solution

  • I can't reproduce your issue on my server with the following script:

    <?php
    $foo='';
    for($i=0; $i < 1000; $i++) $foo .= "cur:$i ";
    var_dump($foo);
    

    Even an additional $foo .= NULL; doesn't trigger the bug for me. Are you really sure that the bug happens on your posted code? Have you tried to add additional debug statements?