views:

285

answers:

2

I have a select() method in a database class, that has an optional boolean argument $sum. This argument is used to say if the method should or not use COUNT(*) too.

I would like to show a warning, like those normal PHP errors, if I try to access class->sum if the attribute is not set (i.e. when I call select() with $sum = false.

Is there any way to show a warning like this, or I should just echo an error and be happy?

+4  A: 

You could try trigger_error()

alex
... Using E_WARNING as the 2nd argument.
too much php
+4  A: 

You're going the object-oriented approach, so I suggest a look into exceptions.

orlandu63
+1 Exceptions will give you the full backtrace information for debugging, whereas trigger_error() will not give you a useful file name / line number.
too much php
Yes, you are right, but an exception for this problem is just so much trouble. It's an easy recoverable non-fatal error, that would happen quickly on developing; triggering an warning is enough to inform the dev about what happened.
Igoru