|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-01-29 19:22 UTC] 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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
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); }