PHP Sadness

Detail in error messages

PHP does a terrible job of providing detail in error messages. For example:

$ cat quotes.php

$string = "welcome to my personal home page;

# a fake example; just imagine some lenghty code here
if ($page_id == 0) {
} elsif ($page_id == 1) {
} elsif ($page_id == 2) {
} elsif ($page_id == 3) {
} elsif ($page_id == 4) {
} elsif ($page_id == 5) {

print "thank you for visiting!";

$ php quotes.php

Parse error: syntax error, unexpected T_STRING in quotes.php on line 20

PHP identifies the issue on line 20, while the real mistake is on line 3. In contrast, here's what Perl does in the same situation:

$ perl
Bareword found where operator expected at line 20, near "print "thank"
  (Might be a runaway multi-line "" string starting on line 3)
        (Do you need to predeclare print?)
Unquoted string "visiting" may clash with future reserved word at line 20.
syntax error at line 20, near "print "thank you "
Can't find string terminator '"' anywhere before EOF at line 20.

Note especially that second line not only points the developer to the correct location, but also describes exactly what it thinks is happening.

Significance: Fast Debugging

It is very important to be able to quickly debug issues in your application. When every second of downtime costs your company money, bad error messages can mean thousands of dollars in unnecessary losses and hours of wasted developer time. Languages posing to be used in large applications need to ensure that developers can quickly discern the cause of an issue.