You are here: Re: do professional PHP programmers use error checking in their code? « PHP Programming Language « IT news, forums, messages
Re: do professional PHP programmers use error checking in their code?

Posted by Chung Leong on 09/04/06 01:13

Peter Fox wrote:
> * Distinguish between
> - Errors and exceptions (Exceptions are where something doesn't work
> as normal. Errors are where an incorrect result/action is obtained.)

Making that distinction is important. That's where the colleague of the
OP erred. Error handling/reporting in PHP is different not because it's
a scripting language. It's different because it's designed for web
application. Unlike desktop apps, the operating environment for web
apps is usually controlled by the programmer. That allows PHP to make
the assumption that any error encountered is a programming error and
accordingly, throwing up a message to inform the programmer. Take
fopen() for instance. In a desktop app it could fail in normal
circumstances (end-user mistake etc.) In a PHP app, when it fails it
usually means the programmer did something wrong, as the file being
opened can either be a file that's part of the app or a file uploaded.
The guy is correct is saying that it's pointless to do what PHP does
for you already.

> For example if (in the UK) I ask for a date then I want it in
> day-month-year order. But you might be used to m-d-y and input to my
> form like that.

That's not a terribly good example, I must say. User errors should
always be expected. Handling them is part of a application's basic
functionality.

> What does the function getRow() return? Here I'll assume it is an alias
> for mysql_fetch_array() which returns FALSE if there's a problem. So if
> the result is to be tested it is good practice to test according to the
> signals in the documentation.
> if(FALSE===getRow($result)){

I didn't mention it since it's just an example, but there is really no
way for that condition to arise. If mysql_num_rows() succeeds, then
mysql_fetch_array() cannot fail, since the rows are in memory already.

> So spend less time on fancyfying the bits that you think might go wrong
> and more on discovering what the important failure modes are; and
> understanding the context in which the information is going to be used.

The only real failure modes are (a) the DB connection is bad, or (b)
the table weblogs is missing or don't have the right column names.
PHP's error reporting mechanism would inform you of both. If one wants
to be helpful, then say something that's actually informative like "the
database schema is incorrect, run create_tables.php to create the
database." Otherwise, if all you're writing are messages in the vein of
"an error happened," then you might as well leave it to PHP.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация