php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49612 require_once() include twice the same file
Submitted: 2009-09-21 13:04 UTC Modified: 2009-09-24 12:18 UTC
From: l dot mauri at neopost dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.2.11 OS: Solaris 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: l dot mauri at neopost dot com
New email:
PHP Version: OS:

 

 [2009-09-21 13:04 UTC] l dot mauri at neopost dot com
Description:
------------
Hello everyone,

I have a problem with my installation of PHP 5.2.11 (please see my
configuration below)

I'm using require_once to include twice the same file. In one case I'm
including the file based on its relative path and in other case I'm
including it with its absolute path.

When I use the php client in command line, it works fine. I only have the problem using Apache server.

I figured out that realpath can't resolve the relative path:
<?php
   print realpath("./file2.php") . "\n";                  ==> FALSE
   print realpath("/absolute/path/to/file2.php') . "\n";  ==> /
absolute/path/to/file2.php
?> 

Thank you in advance

----------------------------------------------------------------
Configuration:
SunOS devs0004 5.10 Generic_137137-09 sun4u sparc SUNW,Sun-Fire-V240
64-bit sparcv9 kernel modules

PHP 5.2.11
Configure Command =>  './configure'  '--with-libxml-dir=/usr/local' '--
with-mysql=/usr/local/mysql5136/' '--enable-track-vars' '--enable-
libgcc' '--enable-trans-sid' '--enable-ftp' '--enable-pcntl' '--enable-
sockets' '--enable-soap' '--with-apxs=/usr/apache/bin/apxs' '--with-
zlib-dir=/usr/local/lib' '--with-pdo-mysql=/usr/local/mysql5136' '--
with-mcrypt=/usr/local/bin' '--enable-debug'

$ file /usr/local/bin/php
/usr/local/bin/php: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, not stripped

$ file /usr/apache/libexec/libphp5.so
/usr/apache/libexec/libphp5.so: ELF 32-bit MSB dynamic lib SPARC Version 1, dynamically linked, not stripped

Apache 1.3.41


Reproduce code:
---------------
file1.php
<?php

require_once('./file2.php');
require_once('/absolute/path/to/file2.php');

$a = new A();
?>
----------------------------------------------------------------
file2.php
<?php
class A
{
    public function foo() { echo 'Foo'; }
}
?>

Expected result:
----------------
The second call to require_once does not include the file.

Actual result:
--------------
PHP raise a Fatal Error : "Fatal error: Cannot redeclare class"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-21 17:59 UTC] jani@php.net
Are there any symlinks involved..?
 [2009-09-24 12:18 UTC] l dot mauri at neopost dot com
Sorry this problem is not due to PHP.

I run truss on httpd process and in fact some open syscall failed but there are no error messages anywhere about that.

Excuse me for the inconvenience.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 14:01:30 2024 UTC