开发者

List of all the possible PHP errors

Sometimes, while coding in PHP we get parse or syntax errors like those:

Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in /var/www/example/index.php on line 4

I would like to know, if there is a list of all possible errors tha开发者_如何学Pythont PHP interpreter can output. I've searched php.net, but couldn't find such thing. I need this list for academic purposes.


No there is no good way. Even the suggested grep for zend_Error() is useless. The errors of the kind you're showing in the question is mostly generated by the bison parser generator and PHP simply takes it from there. Similar things happen with errors reported by the operating system (like errors when opening files). The PHP developers can't really generate a good list for these as the errors depend on the operating system it is running on and versions used while compiling.

The only thing grepping for zend_error() and php_Error_docref() can show you is a general overview of possible error kinds but by far not all error messages.


I don't know if exists a comprehensive list of the possible PHP errors, but about parser errors you should checkout the list of PHP Parser tokens

http://php.net/manual/en/tokens.php

here's what the manual says:

Various parts of the PHP language are represented internally by types like T_SR. PHP outputs identifiers like this one in parse errors, like "Parse error: unexpected T_SR, expecting ',' or ';' in script.php on line 10." You're supposed to know what T_SR means. For everybody who doesn't know that, here is a table with those identifiers, PHP-syntax and references to the appropriate places in the manual.


i'm not aware of such a list, but you can always download or checkout php sources and do something like

 find . -name "*.c" | xargs grep "zend_error"


If you're looking for a list of all possible error types, this will help: http://www.php.net/manual/en/errorfunc.constants.php


This gives 1346 hits for me on the latest PHP source (including duplicates). It may be a good way to go, however the list far from complete due to the reasons outlined by @johannes.

On the other hand, it's going to be extremely difficult to define a specific type of parse error anyway, as I imagine they are compiled by parser during runtime, and are not listed anywhere in the source.

Can you elaborate on what you need this for? Maybe you can define a "sub-class" of errors that is already sufficient for what your need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜