Req #68951 [Opn->Fbk]: Function to check file for parse errors.

From: Date: Thu, 29 Jan 2015 22:28:54 +0000
Subject: Req #68951 [Opn->Fbk]: Function to check file for parse errors.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190325@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68951&edit=1 ID: 68951 Updated by: danack@php.net Reported by: mmorris at tombras dot com Summary: Function to check file for parse errors. -Status: Open +Status: Feedback Type: Feature/Change Request Package: Unknown/Other Function Operating System: Irrelevant PHP Version: Irrelevant Block user comment: N Private report: N New Comment: PHP has a linter invoked with "-l", which, as you guessed, is best run in a separate process. Does that not suit your needs? <?php $output = []; $return_var = null; //The 2>&1 redirects error output to the stdout, so that it can be captured. exec("php -l invalid.php 2>&1", $output, $return_var); if ($return_var === 0) { echo "it as okay."; } else { echo "Something went wrong\n"; var_dump($output); } Previous Comments: ------------------------------------------------------------------------ [2015-01-29 19:22:05] mmorris at tombras dot com Description: ------------ A lot of PHP packages out there run 3rd party code that may contain errors (Wordpress, Drupal, Joomla off the top of my head). It would be very useful to all of them if there was a function that could check a file for parse errors and verify that all proposed function, constant and class names are available for occupation and that they actually exist (although no load would occur, and the autoloader needs to support checking for a class without loading it as it should already do for the existing class_exists() function) without running include or require and finding out that isn't the case with a total system crash. Perhaps include_validate()? Aside from the backwards compatibility problems, I would imagine the engine would have to compile everything twice in order to allow for this, which too large a performance hit to add to the current include and require statements. As separate functions they make sense though. For example, Drupal could use this function to inspect the PHP files of a module during the install process without actually running any of the code, or before running it, and refuse to install a module that can't pass validation. Having a parse error in the middle of the module install process can cause problems. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68951&edit=1

« previous php.bugs (#190325) next »