php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67689 require_once and include_once both fail to recognize previously included file
Submitted: 2014-07-26 23:08 UTC Modified: 2016-07-14 11:37 UTC
From: albertnelsen at earthlink dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.15 OS: Linux Debian Wheezy
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: albertnelsen at earthlink dot net
New email:
PHP Version: OS:

 

 [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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-28 03:36 UTC] yohgaki@php.net
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?
 [2016-07-14 11:37 UTC] dmitry@php.net
-Status: Open +Status: Not a bug
 [2016-07-14 11:37 UTC] dmitry@php.net
"\\" directory separator works only on Windows.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 11:00:02 2026 UTC