note 85778 added to function.include
| From: | jimmy dot axenhus at gmail dot com | Date: | Wed, 17 Sep 2008 15:17:36 +0000 |
| Subject: | note 85778 added to function.include | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144478@lists.php.net to get a copy of this message | ||
Never use include in an if statement.
<?php
if(include('./foo.php') && $bar = "bar") {
echo "FooBar";
}
?>
This will not include the file foo.php, instad it will for some reason onclude the file
"1" and print:
Warning: include(1) [function.include]: failed to open stream: No such file or directory in (file)
on line (line)
Warning: include() [function.include]: Failed opening '1' for inclusion
(include_path='.;C:\php5\pear') in (file) on line (line)
This will also fail if you write:
<?php
if(include './foo.php' && $bar = "bar") {
echo "FooBar";
}
?>
This will not, however, fail if you write:
<?php
if(include('./foo.php')) {
echo "FooBar";
}
?>
PHP version: 5.2.5
----
Server IP: 80.67.2.2
Probable Submitter: 77.240.65.24
----
Manual Page -- http://www.php.net/manual/en/function.include.php
Edit -- https://master.php.net/note/edit/85778
Del: integrated -- https://master.php.net/note/delete/85778/integrated
Del: useless -- https://master.php.net/note/delete/85778/useless
Del: bad code -- https://master.php.net/note/delete/85778/bad+code
Del: spam -- https://master.php.net/note/delete/85778/spam
Del: non-english -- https://master.php.net/note/delete/85778/non-english
Del: in docs -- https://master.php.net/note/delete/85778/in+docs
Del: other reasons-- https://master.php.net/note/delete/85778
Reject -- https://master.php.net/note/reject/85778
Search -- https://master.php.net/manage/user-notes.php