tags:

views:

222

answers:

4

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 that PHP interpreter can output. I've searched php.net, but couldn't find such thing. I need this list for academic purposes.

UPDATE: Thank you for help, everybody. Seems there is no such list because of several reasons and I will have to do my research the other way.

+2  A: 

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"
stereofrog
I've considered this. If there is no documentation on errors, I will have to do so.
Silver Light
+3  A: 

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.*

Ican Zilb
Thanks this list is quite useful for me too!
Silver Light
-1 this is good to know, but how is it related to error messages?
Pekka
@Pekka: This link gives you the list of tokens by name, so you can see what token in your code invokes a parser error, thus you can solve your parse error, please read the short intro at the top of the page at http://php.net/manual/en/tokens.php
Ican Zilb
@Ican he is not about parser errors specifically if I understand him correctly. He wants a comprehensive list of *all* PHP errors for research.
Pekka
ok let's put it this way: from the token list provided, Konstantin can generate himself a list of all possible PARSE ERRORS, provided the case he cannot find a comprehensive list of all possible errors. It's a partial solution to his problem
Ican Zilb
A: 

Following stereofrog's advice 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.

Pekka
+3  A: 

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.

johannes