CDC Update

While using cdc recently after having written about it, I ran into an odd issue. While doing a lint check on a code block, a parse error was occurring on a line that contained a comment in the original source file.

The original code block to do this lint check had the line below to do the heavy lifting.

$response = shell_exec('echo ' . escapeshellarg($code) . ' | php -l');

A var_dump() on $code revealed this, where the comment line was the line on which the parse error was occurring.

string(474) "<?php
...
// Matches any of the standard escape sequences \r, \n, or \t
$matches = (preg_match('/\\r|\\n|\\t/', $string) == 1); 
...
?>"

Presumably what was happening was, even though the var_dump() call showed that actual newlines were being interpreted correctly, the \r was also being interpreted rather than taken literally. This caused the comma following it to generate the error I was receiving, namely "Parse error: syntax error, unexpected ‘,’." (If you know why this is, I’m very curious to find out.)

Luckily I was able to tag Derick and he pointed me in the direction of an alternative: proc_open, which even has an example for executing a PHP file that works just as well when modified to perform a lint check on a PHP file. You can see the code changes in the related git commit.

One Comment

  1. Matthew Turland’s Blog: CDC Update (or an Unusual Parse Error) : Dragonfly Networks says:

    …ews/12311">Matthew Turland’s Blog: CDC Update (or an Unusual Parse Error)
    Matthew Turland came across an interesting bug when working with the Cares Document Checker