Having trouble: Latest SLIM, php 7.1.4, syntax error in slim code

Hi,
Firstly we’re loving SLIM. We have used it for a REST web service for an EXTJS 6 web & mobile application & it’s going well, working with a mySQL database on a Linode VPS.

We are now moving on to a new (similar) project, again using the latest slim download but in this case we’re using a SQL Server database hosted on AWS. We also have the SLIM REST Web Service running on AWS. All this is actually working fine.

To be able to use Microsoft’s SQL Server ‘bits’ with PHP we had to upgrade our PHP to 7.x. & apache 2.4
On my Mac where I develop & test the web applications, I needed to upgrade to php 7.1.4 to get the Microsoft bits to work.
I want to be able to develop & test run the SLIM web service on m Mac for convenience (as I had done for the first project during development)

Now the issue: I can get a response from the SLIM api but the consistent problem is this syntax error.
Parse error: syntax error, unexpected ‘>’ in /Users//Sites//api/vendor/slim/slim/Slim/Handlers/PhpError.php on line 177
this is on both a POST and a GET (I assume for others as well)

My associate has his environment working fine with the same api code, same PHP version, same apache version but Windows 10

Any clues?

Thanks
Roger

Check your line 177 in Slim\Handlers\PhpError.php. It should be:

$xml = "<error>\n  <message>Slim Application Error</message>\n";

Wonder why PHP_EOL was not used, that should be platform-independent.

Hi akrabat

Yes. I had checked that & then re-downloaded it all again to be sure.
$xml = "<error>\n <message>Slim Application Error</message>\n";

and if I add a couple of blank lines … the error says it’s on line 179 … so it’s definitely that line of code that’s upsetting the system.

I changed all the double quotes to single quotes and that sorted that error out, but now I have:
Parse error: syntax error, unexpected end of file in /Users/myName/Sites/projectName/api/vendor/slim/slim/Slim/Handlers/PhpError.php on line 206

I tried putting ?> at line 206, made no difference.

Try this and see how it goes:

protected function renderXmlErrorMessage(\Throwable $error)
{
    $xml = "<error>" . PHP_EOL;
  $xml .= "<message>Slim Application Error</message>" . PHP_EOL;
    if ($this->displayErrorDetails) {
        do {
            $xml .= "  <error>";
            $xml .= "    <type>" . get_class($error) . "</type>"  . PHP_EOL;
            $xml .= "    <code>" . $error->getCode() . "</code>"  . PHP_EOL;
            $xml .= "    <message>" . $this->createCdataSection($error->getMessage()) . "</message>" . PHP_EOL;
            $xml .= "    <file>" . $error->getFile() . "</file>"  . PHP_EOL;
            $xml .= "    <line>" . $error->getLine() . "</line>"  . PHP_EOL;
            $xml .= "    <trace>" . $this->createCdataSection($error->getTraceAsString()) . "</trace>"  . PHP_EOL;
            $xml .= "  </error>"  . PHP_EOL;
        } while ($error = $error->getPrevious());
    }
    $xml .= "</error>";
    return $xml;
}

Thanks SVL.
I tried that, got the same (original) error. changed double quotes to single quotes and got the new error: unexpected EOF at line 206

I suspect this might be caused by a php.ini setting that I don’t know about… perhaps

Looks like something dodgy happened during download-install.
There are issues with double quotes in other places.
I have finally got phpErrorHandler.php working nicely and it’s reporting issues … all to do with double quotes where single quotes should be.

eg. line 173 in /vendor/monolog/monolog/src/Monolog/Formatter/LineFormatter.php
return str_replace(array("\r\n", "\r", "), ' ', $str); . << one double quote
should be
return str_replace(array("\r\n", "\r", ''), ' ', $str); << two single quotes fixes it

OK. Good News

There were only 3 issues in total
1 in phpError.php in the renderXmlErrorMessage method
Fix = replace all double quotes with single quotes in that method.

2 in Monolog/Formatter/LineFormatter.php
1 at line 144. $str .= [stacktrace]\n".$e->getTraceAsString(); >> $str .= '[stacktrace]\n'.$e->getTraceAsString();
1 at line 173. return str_replace(array("\r\n", "\r", "), ' ', $str); >> return str_replace(array("\r\n", "\r", ''), ' ', $str);

Might help someone else in the same boat.

Regards
Roger