|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-02-04 16:58 UTC] saskia at sa5kia dot nl
Description: ------------ The information on the file_exists() function on http://nl2.php.net/file_exists is very wrong. I spend an hour to find out what the problem of my script was, but your manual was the one that was wrong. It sais the function gives a TRUE or a FALSE as an output, but this is very incorrect. It outputs 1 or 0. This is absolutely not the same on unix systems. TRUE or FALSE are boolean values, integers 1 or 0 are used for this a lot, but are INTEGERS. "If" statements in php will NOT recognize the boolean and will not function correctly when treated as one. Please just say a function outputs 0 or 1, if it outputs 0 or 1. Reproduce code: --------------- $does_the_file_exist = "yes"; if ( ! file_exists( "some_not_an_existing_file" ) ) { $does_the_file_exist = "no" } Expected result: ---------------- The value of $does_the_file_exist is "yes", but it should be "no". PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 00:00:02 2026 UTC |
The function does indeed return boolean values: <?php var_dump(file_exists(__FILE__)); var_dump(file_exists('something_else_doesnt_exist')); yeilds: bool(true) bool(false) PHP also casts variables too boolean when required, 1 would cast to be true, 0 to false. So if (1) { echo 1; } will indeed echo 1.