PHP Sadness

Detail in error messages

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

$ cat quotes.php
<?php

$string = "welcome to my personal home page;

# a fake example; just imagine some lengthy code here
if ($page_id == 0) {
  render_home_page();
} elseif ($page_id == 1) {
  render_contacts_page();
} elseif ($page_id == 2) {
  render_about_page();
} elseif ($page_id == 3) {
  render_services_page();
} elseif ($page_id == 4) {
  render_weather_page();
} elseif ($page_id == 5) {
  render_news_page();
}

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 quotes.pl
Bareword found where operator expected at quotes.pl 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 quotes.pl line 20.
syntax error at quotes.pl line 20, near "print "thank you "
Can't find string terminator '"' anywhere before EOF at quotes.pl 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.