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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 22:01:33 2025 UTC