|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-07-26 23:08 UTC] albertnelsen at earthlink dot net
Description:
------------
I'm using:
PHP 5.5.15-1~dotdeb.1 (cli) (built: Jul 24 2014 16:44:04) on
Linux unmapped 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
if you attempt to require_once or include_once the same file where the path differs only by the use of backslashes instead of forward slashes, PHP will attempt to include the file a second time.
Test script:
---------------
//Test1:
require_once "src/ClassA.php";
require_once "src/ClassA.php";
//Test2:
require_once "src\\ClassA.php";
require_once "src\\ClassA.php";
//Test3:
require_once "src/ClassA.php";
require_once "src\\ClassA.php";
//Test4:
require_once "src\\ClassA.php";
require_once "src/ClassA.php";
Expected result:
----------------
For this to work you need a file in the src/ClassA.php directory. Preferably one that declares and defines the ClassA class.
Test1: This code should only include the file once and produce no errors.
Test2: This code should only include the file once and produce no errors.
Test3: This code should only include the file once and produce no errors.
Test4: This code should only include the file once and produce no errors.
Actual result:
--------------
Test1: This code only includes the file once and produces no errors.
Test2: This code only includes the file once and produces no errors.
Test3: This code attempts to include the file twice resulting in a "Cannot redeclare class" error if the file contains a declaration of ClassA.
Test4: This code attempts to include the file twice resulting in a "Cannot redeclare class" error if the file contains a declaration of ClassA.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 01:00:01 2026 UTC |
I got different results from 5.4/5.5/5.6 (all of them are git checkout) with Fedora 20 x86_64. Same for fedora provided PHP 5.5. Debian might have patch for this. Fatal error: require_once(): Failed opening required 'src\ClassA.php' (include_path='.:/usr/local/php5.6/share/pear') in /home/yohgaki/workspace/ext/git/oss/php.net/PHP-5.6/t.php on line 3 [yohgaki@dev PHP-5.6]$ cat t.php <?php require_once "src/ClassA.php"; require_once "src\\ClassA.php"; "/" works under Windows as well as "\\". Thus, users are recommended to use "/" regardless of OS. Are we going to fix this?