note 82329 added to function.file-exists

From: Date: Sat, 05 Apr 2008 23:57:27 +0000
Subject: note 82329 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-137972@lists.php.net to get a copy of this message
I've encountered the same problem as stuart. file_exists() returns false falses if you use a constant as part of the filename when calling it. Putting the same filename into a variable beforehand and specifying that instead works. <? define("CLASS_DIR", "/home/web/classes"); $class_name = "Page"; $dirs = array("", "data/", "output/", "ebay/"); // Does not work foreach($dirs as $dir){ if(file_exists(CLASS_DIR.$dir.$class_name.".class.php")) require_once(CLASS_DIR.$dir.$class_name.".class.php"); } // Works foreach($dirs as $dir){ $filename = CLASS_DIR.$dir.$class_name.".class.php"; if(file_exists($filename)) require_once($filename); } ?> ---- Server IP: 83.170.119.58 Probable Submitter: 87.194.111.28 ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- https://master.php.net/note/edit/82329 Del: integrated -- https://master.php.net/note/delete/82329/integrated Del: useless -- https://master.php.net/note/delete/82329/useless Del: bad code -- https://master.php.net/note/delete/82329/bad+code Del: spam -- https://master.php.net/note/delete/82329/spam Del: non-english -- https://master.php.net/note/delete/82329/non-english Del: in docs -- https://master.php.net/note/delete/82329/in+docs Del: other reasons-- https://master.php.net/note/delete/82329 Reject -- https://master.php.net/note/reject/82329 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137972) next »