Req #70507 [NEW]: Combination of is_file() + include (e.g. "include_if_exists")

From: Date: Tue, 15 Sep 2015 18:03:07 +0000
Subject: Req #70507 [NEW]: Combination of is_file() + include (e.g. "include_if_exists")
Groups: php.standards 
Request: Send a blank email to standards-+get-855@lists.php.net to get a copy of this message
From: andreas at dqxtech dot net Operating system: Linux PHP version: 7.0.0RC2 Package: PHP Language Specification Bug Type: Feature/Change Request Bug description:Combination of is_file() + include (e.g. "include_if_exists") Description: ------------ For slightly improved class loader performance, it would be nice to have a combination of is_file() + include, as a new language construct. Currently, include raises a warning if the file does not exist, is not accessible, or is not a file. This means that a class loader cache that is not sure if the file exists needs to call is_file() before include. And to be strict, it would also have to call is_readable(). The new language construct would include the file if it exists, and return either TRUE or FALSE to indicate the success. This way the script does not need to hit the filesystem more than once. An explicit return value of the file can be ignored, because this is mostly designed for class files. There could be some more interesting behavior on failure. E.g. instead of just returning FALSE, it could return an object with an indication what went wrong.. Or this information could be retrieved from elsewhere. The goal is to optimize the performance in case of success, not on failure. ------- This being said: Maybe this is all not necessary, if the compiler/optimizer can automatically merge the is_file() and the include. Test script: --------------- spl_autoload_register('my_autoload_callback'); function my_autoload_callback($class) { $file = my_autoload_cache_lookup($class); if (!$file) { return; } if (true === include_if_exists $file) { // Done with the classloader. return; } my_autoload_cache_unset($class); $file = my_autoload_psr4_lookup($class); if (!$file) { return; } if (true === include_if_exists $file) { my_autoload_cache_set($class, $file); } } -- Edit bug report at https://bugs.php.net/bug.php?id=70507&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70507&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70507&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70507&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70507&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70507&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70507&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70507&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70507&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70507&r=support Expected behavior: https://bugs.php.net/fix.php?id=70507&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70507&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70507&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70507&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70507&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70507&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70507&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70507&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70507&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70507&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70507&r=mysqlcfg

« previous php.standards (#855) next »