Ticket #418 (closed enhancement: fixed)
Minor improvement for PhpLintTask
| Reported by: | pigulla@… | Owned by: | mrook |
|---|---|---|---|
| Priority: | low | Milestone: | 2.4.1 |
| Component: | phing-tasks-ext | Version: | devel |
| Keywords: | phplint, deprecated | Cc: |
Description
According to the PHP docs, 'php -l' returns 0 for syntactically valid files and -1 otherwise. The task, however, currently ignores this return value. Hence, the regex in line 201 of PhpLintTask::lint() is not really needed and can be removed, potentially speeding things up a bit:
Change:
$messages = array(); exec($command.'"'.$file.'"', $messages); if(!preg_match('/No syntax errors detected/', $messages[0])) {
To:
$messages = array(); $retVal = null; exec($command.'"'.$file.'"', $messages, $retVal); if($retVal == -1) {
Attachments
Change History
Changed 2 years ago by pigulla@…
-
attachment
patch.diff
added
comment:1 Changed 2 years ago by pigulla@…
Actually, I did miss something here: php returns 0 for files that parse, but throw deprecated warnings. In my particular case, this is not desired as I want PhpLintTask to log those as well. It'd probably be very useful to make PhpLintTask configurable, so one can toggle an options such as "treatDeprecatedAsError" as needed.
comment:2 Changed 2 years ago by mrook
Excuse the late reply - so what behavior would you like to see in PhpLint?
comment:3 Changed 2 years ago by anonymous
Ideally, I want to be able to select whether or not PhpLintTask should treat "deprecated" warnings as errors, i.e. cause the build process to fail (maybe I should open a new ticket for this as it isn't really related to the change I originally posted).
comment:4 Changed 2 years ago by mrook
Ok -- do you have a sample of the message(s) PHP emits with deprecated code? I have no 5.3 installation ready.
comment:5 Changed 2 years ago by anonymous
Example (test.php):
$foo =& new stdClass();
bar(&$foo);
function bar($baz) {}
Output:
peter@pan:~$ php -l -d error_reporting="E_ALL|E_DEPRECATED" test.php PHP Deprecated: Assigning the return value of new by reference is deprecated in test.php on line 3 PHP Deprecated: Call-time pass-by-reference has been deprecated in test.php on line 5 No syntax errors detected in test.php
There can of course be both deprecated warnings as well as parse errors.

Diff for trunk