[dev] Driver capability assertions

Rich Lafferty rich@horde.org
Fri, 16 Feb 2001 22:38:06 -0500


On Fri, Feb 16, 2001 at 09:19:37PM -0500, Jon Parise (jon@csh.rit.edu) wrote:
> I was thinking of adding capability assertions to those drivers that
> require non-standard PHP extensions.  For example, I might add
> something like this to all of the LDAP drivers:
> 
>     if (!function_exists('ldap_connect')) {
>         echo 'LDAP support is required by this driver.';
>         exit;
>     }

I like this. :-)
 
> Or we could use PHP's assert() function:
> 
>     assert(function_exists('ldap_connect'));

I don't like this -- this is the sort of thing where you'd otherwise
do

    // Cannot reach this point
    exit;

Assertions should only be used in places where there is absolutely no
way for the program to continue, even to exit normally, given that the
assertion failed. 

I've always considered assertions to be safety mechanisms to check up
on the programmer, not the end user.

   -Rich

-- 
------------------------------ Rich Lafferty ---------------------------
 Sysadmin/Programmer, Instructional and Information Technology Services
   Concordia University, Montreal, QC                 (514) 848-7625
------------------------- rich@alcor.concordia.ca ----------------------