调用方法会产生不同的结果

I want to collect some data from a 3rd party page. I use http://simplehtmldom.sourceforge.net/ for this. In the construct I get the select item from the page and I pass it to the loopSelect($html), which loops through the options (some product category), and whit the new parameter (product category) it makes a POST call to the page. The server returns a string (the select box of the subcategories).

The problem:

The line var_dump($select); returns empty string. If I remove the line $type = $this->getBetween... it works as expected, I can see the select's string with each subcategory for each product category.

/**
 * 
 * @param array $search
 * @return string
 */
function getSelect(array $search = [])
{        
    $default = [
        'option' => 'com_batteryfinder',
        'format' => 'raw',
        'controller' => 'batteryfinder',
        'task' => 'getdropdown',
    ];

    $data = array_merge($default, $search);
    var_dump($data);
    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded
",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    return file_get_contents($this->url, false, $context);               
}


function loopSelect($html)
{
    $name = $html->find('select',0)->getAttribute ( 'name' );
    foreach($html->find('option') as $option)
    {
        if ($option->value)
        {
            $this->formData[$name] = $option->value;

            $select = $this->getSelect($this->formData);

            var_dump($select);

            $type = $this->getBetween($select, "loadSearchSelect(options, '", "');");

        }
    }         
}

Looks like calling a method getBetween messes up everything.

function getBetween($out, $start, $end)
{
    if (strpos($out, $start) === false)
    {
        return FALSE;
    }        
    $startsAt = strpos($out, $start) + strlen($start);


    $endsAt = strpos($out, $end, $startsAt);
    if ($endsAt=== FALSE)
    {
        return FALSE;
    }
    return substr($out, $startsAt, $endsAt - $startsAt);        
}

EDIT

passing $select into a new variable seems to solve the problem, but I don't get it why?

        $this->formData[$name] = $option->value;

        $select = $this->getSelect($this->formData);

        var_dump($select);

        $out = $select;

        $type = $this->getBetween($out, "loadSearchSelect(options, '", "');");
        var_dump($type);

Sorry if I'm about to be too obviuos, but, have you got display errors active? May getBetween be causing some error that is not being displayed and finishes the execution of the script? Or var_dump is showing a 'String(0) ""' or like, and the script finishes ok.

Anyway, why aren't you using regular expressions to implement getBetween function?