0

I'm developing a plugin system, which of course needs to include the plugin files. So far everything works very well - exceptions get catched etc.

But my very last wish would be to even be safe from corrupt plugin files containing syntax errors. Is there a way to catch Fatal Errors in included files?

0

1 Answer 1

4

There is runkit_lint() that requires PHP runkit, or simply run php with the -l option for Lint:

if(strpos(exec('/path/to/php -l filename.php'), 'No syntax errors detected') !== false) {
    // file parses :-)
} else {
    // parse errors :-(
}

Or similar logic. Note that this only checks for parse errors not fatal errors (require fails, etc.)

2
  • So basically I need to precheck every file before actually including it? Is runkit eventually cheaper in terms of performance?
    – Robert
    Commented Mar 23, 2015 at 10:43
  • I haven't bench-marked, but you could lint the files once and save the "safe" ones in the db or file and check that on subsequent calls and only check new files. Commented Mar 23, 2015 at 13:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.