How to handle attempt to set non-existent configuration?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

How to handle attempt to set non-existent configuration?

Post by Ambush Commander »

How should a library handle an attempt to set a non-existent configuration directive?

On one hand, if it doesn't exist, you probably ought to tell the user right away. Maybe it's a typo or something.

On the other hand, a lot of software packages don't complain when a non-existent value is set. The say "Oh, maybe it's used in a future/past version, no problem-o!" PHP, for example.

Right now, I'm fatally error'ing out. What do you think I should do?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Built properly, this system is fairly future proof and therefore should know which directives are correct. So erroring out immediately (or so some catching system) would likely be the best course.

If in development mode it could even try to suggest the correct directive.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

for "non-existant" stuff, perhaps a notification and continue as per norm, ignoring it? ala Notice errors in php.. or perhaps warning level (Warning: config option blah ignored. continuing normal operations..)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well, therein lies the problem. Notices are usually ignored... not everyone even has them turned on. Warnings are a bit better, but they're not as in your face as a fatal error.

I'm pretty sure I know what my options are, so I'm more interested in rationale behind making the error fatal or not.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Image

This choice seems like it may narrow down to "who is my audience?" If the answer is other (decently) experienced developers, then fatals sound fine. If on the other hand this is a drop-in or intended for complete novices then I'd sway toward swallowing the error while still firing a warning or notice.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well, since the documentation around configuration is near non-existent, I think I'll opt for the advanced developer audience for now, and then bump it down once I officially release the functionality. Thanks Feyd!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

They don't have to be E_USER_NOTICE/WARNING.. you can generate your own error that can't be simply switched off with display_errors()
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Ability for user to set with default as fatal?

Code: Select all

DirectivesControlClass::setExistanceFailureHandleMethod(DirectivesControlClass::FATAL);
DirectivesControlClass::setExistanceFailureHandleMethod(DirectivesControlClass::NOTICE);
DirectivesControlClass::setExistanceFailureHandleMethod(DirectivesControlClass::IGNORE);
You might wanna use a shorter function name :P
Post Reply