php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43380 incorrect file_exists() results in destructors
Submitted: 2007-11-22 17:58 UTC Modified: 2007-11-24 12:26 UTC
From: orlandu96 at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.5 OS: Windows XP SP2
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: orlandu96 at gmail dot com
New email:
PHP Version: OS:

 

 [2007-11-22 17:58 UTC] orlandu96 at gmail dot com
Description:
------------
file_exists() always returns false for relative URIs when called in a class destructor.

Reproduce code:
---------------
class test {
	public $file = 'index.php';
	
	function checkFile() {
		if(file_exists($this->file)) {
			echo "{$this->file} exists";
		} else {
			echo "{$this->file} doesn't exist";
		}
		echo "\n";
	}

	function __destruct() {
		echo 'test::__destruct() : ';
		$this->checkFile();
		echo 'test::__destruct() : ';
		if(file_exists(__FILE__)) {
			echo __FILE__, ' exists';
		} else {
			echo __FILE__, ' doesn\'t exist';
		}
	}
}

$test = new test;
echo 'test::checkFile() : ';
$test->checkFile();

Expected result:
----------------
test::checkFile() : index.php exists
test::__destruct() : index.php exists
test::__destruct() : C:\xampp\htdocs\templating\index.php exists

Actual result:
--------------
test::checkFile() : index.php exists
test::__destruct() : index.php doesn't exist
test::__destruct() : C:\xampp\htdocs\templating\index.php exists

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-24 12:24 UTC] jani@php.net
Try checking the current working directory using getcwd(). I bet it's not what you expect.
 [2007-11-24 12:26 UTC] jani@php.net
See bug #42626

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 16:01:35 2024 UTC