Re: Re: [PEPr] Comment on RFC::EvalForbiddance

From: Date: Tue, 16 Aug 2005 17:30:08 +0000
Subject: Re: Re: [PEPr] Comment on RFC::EvalForbiddance
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-39424@lists.php.net to get a copy of this message
Clay Loveless (clay@killersoft.com) wrote: > $is_a = eval("return (\$p instanceof PEAR) ? true : false;"); > if ($p instanceof PEAR) { > $is_a = true; > } Whoops, left an uncommented section in there. Here's the final script for an example of good use of eval(): <?php require_once 'PEAR.php'; $p =& new PEAR; // The following 3 lines will kill PHP4. Comment them out // to test proper and safe eval() usage. if (class_exists('pear') && $p instanceof PEAR) { echo "We'd never reach this line with PHP4."; } $is_a = false; $major_php_version = PHP_VERSION; if (intval($major_php_version{0}) < 5) { if (is_a($p, 'pear')) { $is_a = true; } } else { $is_a = eval("return (\$p instanceof PEAR) ? true : false;"); } // Safe detection with PHP4 _and_ PHP5. if ($is_a) { echo "neato, a PEAR object!\n"; } ?> -- Killersoft.com

« previous php.pear.dev (#39424) next »