Re: Silenced include(_once) calls
| From: | bertrand Gugger | Date: | Fri, 03 Mar 2006 07:21:39 +0000 |
| Subject: | Re: Silenced include(_once) calls | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-41606@lists.php.net to get a copy of this message | ||
bertrand Gugger wrote:
I believe the @open() method is certainly the best solution, should not give much overload. That said, I also consider that is to be used only where something really optionnal exists. After all, taking the example of Text_Wiki, if some implementer does: $wiki = & factory('BBCode'); but s?he did not install the Text_Wiki_BBCode extension, I see no problem to let PHP kill the stuff. The error messages will be quite explicit.Errmmm.... again auto-replying, looks liek I've difficulties to start the engine this morning :) Let me push this argument further and examine the overload. As said, @open will cost quite nothing as the file will be opened anyway by the include. But, as all you do is transforming the PHP fatal in some "gentle" PEAR::Error, then the Text_Wiki::factory() implementer, if s?he does h(er|is) job (half) properly, risks to do: $wiki = & Text_Wiki::factory('BBCode'); if (PEAR::isError($wiki)) { .... Here is the overload: you force to include 'PEAR.php' what we else never need in Text_Wiki OK, it's perhaps only a documentation problem as that can be avoided by doing: if (is_a($wiki, 'PEAR_Error')) { ... which does not need the class to be loaded (not sure about PHP5) ... what does the furnished Text_Wiki::isError() so here, if (Text_Wiki::isError($wiki)) { .... works perfectly. Note that is_a() is deprecated in PH5 in favor of instanceof, but a simple: if ($wiki instanceof PEAR_Error) { ... will not avoid the overload as it will force the autoload of PEAR_Error class, you need: if (|class_exists('PEAR_Error', false) && (|$wiki instanceof PEAR_Error)) { ... as $wiki cannot be a PEAR_Error without the class having been loaded. I use here the Text_Wiki example, but the same applies to several other packages. Again, why not KISS and just let PHP error handling do the stuff, it's here an implementation choice, no uncheck user input. Another example I know well is Net_Monitor, if you configure some SMS alerter and you did not install Net_SMS then this will die thru PHP error handling, and it's perfectly right. (errmmm.... :) I need to change it to include_once 'Net/SMS.php'; not require_once ! The death will be more direct) Regards -- toggg