|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #68951 Function to check file for parse errors.
Submitted: 2015-01-29 19:22 UTC Modified: 2015-02-08 04:22 UTC
From: mmorris at tombras dot com Assigned:
Status: No Feedback Package: Unknown/Other Function
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-01-29 19:22 UTC] mmorris at tombras dot com
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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-29 22:28 UTC]
-Status: Open +Status: Feedback
 [2015-01-29 22:28 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?


$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";
 [2015-02-08 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 11:01:27 2024 UTC