Hi. For those of us still supporting PHP 4, I wonder if you think it is OK to use trigger_error from library code?
For the most part I've usually returned simple error classes from library classes/functions. I've actually never really liked the trigger_error way of doing things in PHP but lately I've been using it more. But I wonder if it's a bad thing to do this from library code because it takes control out of the hands of the user of the library.
And if it is ok to use trigger_error from libraries what levels are OK to use? Would you want to trigger an E_USER_ERROR (fatal) from a library? I would think not but maybe you can give me a reason why it's OK.
Hope to hear your thoughts.
trigger_error from libraries in PHP 4
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
For code that you would normally throw an exception for, trigger_error() is well suited to fill that space in PHP 4.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Errors, unlike Exceptions, should be triggered when something has "gone wrong". If a user passes an invalid parameter, for example, and the library just cannot do anything with it or return a valid value, then it's better to trigger an error and let the user know it's their code (not yours) at fault. It benefits everyone in the end by reducing user level code which assumes your library is working correctly even though it's not.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US