0
votes

I have a strange issue and I can't find why is it happening. Some background first. I have a symfony 1.4 application installed on about 10 production servers. They all run PHP 5.3.0 but I'm not sure if all are configured in the same way (it depends on the admins and I'm familiar with parts of the php.ini file only). So... A strange error was reported a few days ago on one of the servers. After each call of the forward method in an action class (the only important thing about it to symfony non-familiar people is that it does things and throws a sfStopException which inherits the sfException class) a "Fatal error: Only variables can be passed by reference" error is generated. I've searched the web for the reason and here is what I've found - the-stickman.com/web-development/php/php-505-fatal-error-only-variables-can-be-passed-by-reference/. I think this post describes perfectly the problem and the solution. It's all fine so far - nothing strange... Until I saw where the error was generated - .../lib/vendor/symfony/lib/exception/sfException.class.php on line 293 which stands for this method:

/**
 * Returns an excerpt of a code file around the given line number.
 *
 * @param string $file  A file path
 * @param int    $line  The selected line number
 *
 * @return string An HTML string
 */
static protected function fileExcerpt($file, $line)
{
    if (is_readable($file))
    {
        // THIS LINE GENERATES THE ERROR
        $content = preg_split('#<br />#', highlight_file($file, true)); 

        $lines = array();
        for ($i = max($line - 3, 1), $max = min($line + 3, count($content)); $i <= $max; $i++)
        {
            $lines[] = '<li'.($i == $line ? ' class="selected"' : '').'>'.$content[$i - 1].'</li>';
        }

        return '<ol start="'.max($line - 3, 1).'">'.implode("\n", $lines).'</ol>';
    }
}

So... having in mind the explanation why this type of error is generated I understand what the problem is but I cannot think of a good solution. This part of code is not something important for my application actually - it just renders the code of the php files in the symfony stack trace (it's not a big pain that I can't see it on one production server having in mind that it shouldn't be even available there). But the only solution (a quick one) that I've found is just to comment some of this code. Now the users can use my application but this doesn't make me happy because I haven't found a clean solution (I don't like hacking my own application). So... I hope I've described the problem well enough and someone can give me at least some ideas... Thanks :).

EDIT: and here is the php.ini in two parts:
- part 1 - http://pastie.org/2733955
- part 2 - http://pastie.org/2733961
I can paste more php configuration info but I need to know what will be of interest - php.ini is the only php configuration I'm kind of familiar with... Cheers :).

1
Which line is the 293th exactly?Alessandro Desantis
The one that's labeled "THIS LINE GENERATES THE ERROR"Mr. Llama
This code cannot possibly generate that error, unless it's a PHP bug in an old version. None of these functions accept references at any position. Can you post a stack trace?netcoder
Well, this code generates the symfony stack trace code snippets... That's why it is really strange to me. None of the other servers has this error... The apache log says "Fatal error: Only variables can be passed by reference" and that's allmishedone

1 Answers

0
votes

Change $content = preg_split('#<br />#', highlight_file($file, true));
to $content = preg_split('#<br />#', ($hf = highlight_file($file, true)) );
and that should do the trick. (And if not, then we'll be one step closer to the answer.)

Though to be honest, I'm not sure why it'd be throwing a fit. According to the documentation, the second parameter of preg_split is passed by value. Heck, none of those functions in that snippet required pass by reference. But then again, you did say this was just happening on one of the servers, so it may be a configuration error.