php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38579 require_once() distinguishes backslashes from forward slashes
Submitted: 2006-08-24 10:27 UTC Modified: 2006-09-20 08:06 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: frank at procurios dot nl Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.5 OS: Windows
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: frank at procurios dot nl
New email:
PHP Version: OS:

 

 [2006-08-24 10:27 UTC] frank at procurios dot nl
Description:
------------
When including a file, require_once() will make a destinction between path/file strings containing forward slashes and backslashes. 

Reproduce code:
---------------
(example)
function __autoload($className){
    $basePath = 'C:/htdocs';
    $classPath= $basePath . '/classes';
    require_once($classPath . "/$className.class.php");
}

// Some function that doesn't resolves paths
function getPath($file){
   $path = realpath('./$file');
   return $path;
}   

// Autoload
$A = new Foo;

// Explicit require of class
require_once(getPath(Foo.class.php));
$B = new Foo;

Expected result:
----------------
One would expect the require_once to notice that Foo has already been loaded and not include the file a second time.

Actual result:
--------------
Fatal error: Cannot redeclare class foo in c:\htdocs\classes\Foo.class.php on line n

(or something like that)

Whatever the actual result, the file is loaded twice, as the slashes produced by realpath are distinguished from the slashes used in the defined __autoload() function. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-24 10:30 UTC] frank at procurios dot nl
For sake of clarity, a minor typo needs to be corrected:

// Some function that doesn't resolves paths

Should be

// Some function that doesn't do anything but resolve paths
 [2006-08-30 12:29 UTC] taco at procurios dot nl
I'm experiencing this bug too. Besides the slashes also differences in drive letter case seem to interfere with the require_once cache: requiring the path C:/path/file.php in the __autoload function will not prevent the file c:/path/file.php from being required a second time using require_once.
 [2006-09-05 15:52 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2006-09-06 06:39 UTC] dmitry@php.net
The problem is not in slashes, but in case-sensitivity.

The patch doesn't fix anything. I reverted it.
 [2006-09-20 08:06 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_2.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 23:01:29 2024 UTC