|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-02-07 17:21 UTC] michael at gamepoint dot net
When trying to check if include_once succeeded i came up the following bug (i believe):
if( include_once("test1.php") == false ) {
print "Failed to include file";
}
Warning: Failed opening '' for inclusion (include_path='.:/usr/local/lib/php') in /usr/home/michael/www/bug.php on line 6
Removing '== false' removes the problem.
My configuration is:
FreeBSD 4.5
Apache 1.3.22
PHP 4.1.1
Configure options: './configure' '--with-mysql' '--with-apxs'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 12:00:01 2025 UTC |
I already forgot about this bug, but received the email today that this was considered bugus. Well i'm surprised, and tested it a few times more (with a newer php version), and i'm still convinced that this is a bug. A few new examples: <? if( include("include.txt") == true ) { print "File included\n"; } ?> The code above returns this fatal error: Warning: Failed opening '1' for inclusion (include_path='.:/usr/local/lib/php') in /usr/local/apache/htdocs/test.php on line 2 And now i do it the longer way: <? $status = include("include.txt"); if( $status == true ) { printf("File included!\n"); } ?> Works perfectly And another way that works: <? if( true == include("include.txt") ) { print "File included\n"; } ?> The problem really seems what derick@php.net said, a scripting engine bug. PS. Your reply about me asking a support question here is rather weird to me, i was just reporting a bug..confirmed with 4.4.0-dev (cli)/ ZE 1.4.0. i'm including a repro recipe # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # foo.php # bar.inc # echo x - foo.php sed 's/^X//' >foo.php << 'END-of-foo.php' X#!/usr/bin/env php X<? X X if (include('bar.inc') == true) { X print "1. ok\n"; X } X X if (true == include('bar.inc')) { X print "2. ok\n"; X } X X $rv = include('bar.inc'); X if (true == $rv) { X print "3. ok\n"; X } END-of-foo.php echo x - bar.inc sed 's/^X//' >bar.inc << 'END-of-bar.inc' X<? X print "Hello world\n"; X END-of-bar.inc exit> Updated Version The include*/require* functions are a bit inconsistent. In the simple tests done, the filename printed after "Running" is the statement included in the source and executed by PHP, e.g. var_dump(require("file2include")); Every script ran exeutes the same statement twice in a row. First tests done by including the following: <?php echo "File got included\n"; ?> --> Running include.php File got included int(1) File got included int(1) --> Running include_once.php File got included int(1) bool(true) --> Running require.php File got included UNKNOWN:0 File got included UNKNOWN:0 --> Running require_once.php File got included int(1) bool(true) Same tests ran with: <?php echo "File got included\n"; return "Returning a string"; ?> --> Running include.php File got included string(18) "Returning a string" File got included string(18) "Returning a string" --> Running include_once.php File got included string(18) "Returning a string" bool(true) --> Running require.php File got included UNKNOWN:0 File got included UNKNOWN:0 --> Running require_once.php File got included string(18) "Returning a string" bool(true)Because michael did mention this bug again... mfisher already did describe what happens when you use var_dump(include_once("someinclude.inc")) twice. So what's only left is the weird behaviour from the if(include_once("test.php") == false) or == true. when adding a few ()'s it works as expected. if((include_once("test.php"))== $bool){ echo("file test.php included"); } when $bool is 'true', it will echo the line, if $bool is 'false' it will not echo the line. if the file is not found it will produce a warning, and it will display the line when $bool is 'false'. In any case, adding the () around the include() will make the strange Warning: Failed opening '' for inclusion, or Warning: Failed opening '1' for inclusion, go away.Simple explanation for Andi: This does not work: if (include('bar.inc') == true) { print "1. ok\n"; } But this does: if ((include('bar.inc')) == true) { print "1. ok\n"; } Bug or just documentation issue?it seems that this is actually happening because the following statement: if (include_once('file') == FALSE) is actually being parsed as: if (include_once ('file' == FALSE)) becasue include_once isn't a true function. Is that what the docs should say? SThis bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "Because include() is a special language costruct, parentheses are not needed around its argument. Take care when comparing return value. <?php // won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('') if (include('vars.php') == 'OK') { echo 'OK'; } // works if ((include 'vars.php') == 'OK') { echo 'OK'; } ?>