Re: Re: PEAR::DB, function &limitQuery() modification
| From: | John Luxford | Date: | Sat, 08 Feb 2003 06:07:59 +0000 |
| Subject: | Re: Re: PEAR::DB, function &limitQuery() modification | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-13065@lists.php.net to get a copy of this message | ||
On Friday, February 7, 2003, at 02:20 PM, Stig S. Bakken wrote:
This change looks good, with one exception: is_a() exists only in 4.2.0 or later, which is not a dependency I want to introduce to DB.Perhaps PEAR would do well to include something like a "functions" package which implements common functions that either a) don't really belong in any specific package, or b) allow the use of new functions in older versions of PHP. I've used this technique in my own framework in order to achieve (b) more so than (a), but a little of both. :) Here's the code for is_a(), as well as vsprintf(), which I found useful too (that way too if such a package gets accepted, is_a() doesn't have to be alone in there ;)). I believe I may have gotten one or more of these functions from the user contributed notes in the docs (to give credit where it's due). if (! function_exists ('is_a')) { // implement is_a() in PHP < 4.2.0 function is_a ($class, $match) { if (empty ($class)) { return false; } $class = is_object ($class) ? get_class ($class) : $class; if (strtolower ($class) == strtolower ($match)) { return true; } return is_a (get_parent_class ($class), $match); } } if (PHP_VERSION < '4.1.0') { // implement vsprintf() in PHP < 4.1.0 function vsprintf ($str, $args) { array_unshift ($args, $str); return call_user_func_array ('sprintf', $args); } } Then either the package could declare a dependency on it, or it could be auto-loaded with require('PEAR.php'). Downside is that it's more code to load for the users who don't need it. Thoughts? Lux