Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.9.0

Request #12857 Add the option to locally mask exceptions
Submitted: 2008-01-08 18:28 UTC
From: jorrit Assigned: farell
Status: Closed Package: PHP_CompatInfo (version 1.5.1)
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: 1.7.0    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 5 + 21 = ?

 
 [2008-01-08 18:28 UTC] jorrit (Jorrit Schippers)
Description: ------------ With the current version of PHP_CompatInfo, it is only possible to define exceptions globally. If you use for instance ftp_allow() only if it's available (>= PHP 5.0.0), by using function_exists(), it will still list PHP 5.0.0 as minimum requirement. This can only be prevented by specifying a global exception file. What I would like to be able to do is annotate a piece of code with a comment that says: in this piece of code, ignore occurences of ftp_alloc() for version checking. Something like this would be usefull: /**#@+ * @ignorecompat ftp_alloc() */ if (function_exists('ftp_alloc')) { ftp_alloc($this->_handle, filesize($local_file)); } /**#@-*/ Of course this example interferes with PHPDoc, but it's just to give an example. In this way, compatibility issues appearing in different parts of your code are not masked by one exception, which might cause you to miss instances. In addition to that, the exceptions are documented inside the code, instead of in a separate text file, which is nicer in my opinion.

Comments

 [2008-01-12 12:45 UTC] farell (Laurent Laville)
Hello Jorrit, Sorry but i'm against such suggestion. BTW I can propose to you another solution I've just implemented and tested on my local copy of PHP_CompatInfo 1.5.1 Here are my proposal : Add a new option "ignore_function_exists" boolean value (default is false), which can be turn on to detect automatic function_exists code and remove funtion name from parse scope. Example : <?php require_once 'PHP/CompatInfo.php'; $code = <<<EOS if (function_exists('debug_backtrace')) { $backtrace = debug_backtrace(); } else { $backtrace = false; } EOS; $code = "<?php" . PHP_EOL . $code . PHP_EOL . "?>"; $info = new PHP_CompatInfo(); $options = array('debug' => true, 'ignore_function_exists' => true); $res = $info->parseString($code, $options); print_r($res); ?> Will print out result $res like this : Array ( [max_version] => [version] => 4.0.0 [extensions] => Array ( ) [constants] => Array ( ) [function_exists] => Array ( [0] => debug_backtrace ) [4.0.0] => Array ( [0] => Array ( [function] => function_exists [extension] => [pecl] => ) ) ) rather than standard result without option ignore_function_exists (or set to false) Array ( [max_version] => [version] => 4.3.0 [extensions] => Array ( ) [constants] => Array ( ) [function_exists] => Array ( ) [4.3.0] => Array ( [0] => Array ( [function] => debug_backtrace [extension] => [pecl] => ) ) [4.0.0] => Array ( [0] => Array ( [function] => function_exists [extension] => [pecl] => ) ) ) Tell me what you think about it ? Regards, Laurent
 [2008-01-12 14:31 UTC] jorrit (Jorrit Schippers)
To me the specifics of the solution don't matter, I just would like to be able to ignore a function on a call by call basis. If this will allow me to do that, I'm happy!
 [2008-01-12 14:38 UTC] farell (Laurent Laville)
When you told : "I just would like to be able to ignore a function on a call by call basis" If you means on each file parsed (it's ok for me). If you means on each implementation of function exists in a same file (sorry, but in this case I won't fix it)
 [2008-01-12 15:07 UTC] jorrit (Jorrit Schippers)
Well, the best would be this: ... if (function_exists('ftp_alloc')) { ftp_alloc(....); } ..... ftp_alloc(); .... In this case, pci should still indicate that the file needs PHP 5.0.0. The point is that I want to make sure all calls to ftp_alloc() (as an example) are masked by function_exists(). I want to make sure I don't forget to mask a call.
 [2008-01-12 15:31 UTC] farell (Laurent Laville)
In such condition (your latest example), solution is to use "ignore_functions" option and ftp_alloc will be remove from parser scope $options = array('ignore_functions' => array('ftp_alloc')); But this feature already exists in PCI 1.5.1
 [2008-02-17 16:44 UTC] farell (Laurent Laville)
I've decided to re-open the request with this solution : Add three new options to locally auto-detect mask exceptions 1. *ignore_functions_match* : ignore all functions found that will match (using regular expression) the pattern 2. *ignore_constants_match* : ignore all constants found that will match (using regular expression) the pattern 3. *ignore_extensions_match* : ignore all extensions found that will match (using regular expression) the pattern All the three ignore condition options have a hash of two additional parameters: a) the function name that condition code or a valid callback that will check if function/constant/extension should be ingore or not. b) the pattern (regular expression) to try to match Some examples : ======================================== A. I want to ignore all functions that match condition "beginning with ftp_" and only if function exists code will be something like : <code> <?php require_once 'PHP/CompatInfo.php'; $code = <<<EOS if (function_exists('debug_backtrace')) { $backtrace = debug_backtrace(); } else { $backtrace = false; } if (function_exists('ftp_alloc')) { ftp_alloc(....); } //..... ftp_alloc(); EOS; $code = "<?php" . PHP_EOL . $code . PHP_EOL . "?>"; $info = new PHP_CompatInfo(); $options = array('debug' => true, 'ignore_function_match' => array('function_exists', '/^ftp_/') ); $res = $info->parseString($code, $options); ?> </code> "ftp_alloc" will be ignore but not "debug_backtrace" (does not match ignore condition) B. I want to ignore all constants that contains _ERR_ in their names and include with code : if defined('...') $options = ('ignore_constants_match' => array('defined', '/_ERR_/')); C. I want to ignore all extensions that contains dom in their names and include with code : if extension_loaded('dom...') $options = ('ignore_extensions_match' => array('extension_loaded', '/^dom/i')); D. Last but not least, ignore all functions that match condition "beginning with prefix "myfunc" $options = ('ignore_functions_match' => array('preg_match', '/^myfunc/i'));
 [2008-02-21 17:26 UTC] farell (Laurent Laville)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. See also my post in PEAR-dev mailing list about version 1.7.0a1, and feedback/call for testers !!!