Bug #67017 [Com]: include_once() in if statement is taking incorrect parameter
| From: | william75 at yopmail dot com | Date: | Fri, 04 Apr 2014 09:47:30 +0000 |
| Subject: | Bug #67017 [Com]: include_once() in if statement is taking incorrect parameter | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185084@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67017&edit=1
ID: 67017
Comment by: william75 at yopmail dot com
Reported by: seufert at gmail dot com
Summary: include_once() in if statement is taking incorrect
parameter
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Mac OS/X 10.9
PHP Version: 5.6.0alpha3
Block user comment: N
Private report: N
New Comment:
That is no bug, include_once/require_once is a language construct not a function,
so
include_once("myclass.php") === FALSE
can (should) be written as
include_once "myclass.php" === FALSE
which binds like
include_once ("myclass.php" === FALSE)
which evaluates to
include_once FALSE
which converts to
include_once ""
which fails.
Both manual pages for "include_once" (used in your bug summary) and
"require_once" (used in your description and script) ultimately link to the
"include" documentation [ http://www.php.net/manual/en/function.include.php
] which warns about that:
"""
Because include is a special language construct, parentheses are not needed around its argument.
Take care when comparing return value.
Example #4 Comparing return value of include
<?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';
}
?>
"""
Incidentally, testing ((require_once "myclass.php") === FALSE) or (FALSE === require_once
"myclass.php") in your script is useless since, as opposed to include/include_once, a
failing require/require_once will produce a fatal error and stop the execution.
Previous Comments:
------------------------------------------------------------------------
[2014-04-04 07:07:48] seufert at gmail dot com
Description:
------------
Also tested on PHP 5.5.5 on Windows 7 x64
Issue seems to be todo with order of operations, the filename is being ignored, and perhaps FALSE is
being used.
If you change the script to FALSE === require_once(...) it works perfectly.
Test script:
---------------
<?php
if(require_once("myclass.php") === FALSE) {
echo "Hi there was a problem";
}
new myclass();
Expected result:
----------------
No errors
Actual result:
--------------
Inappropriate ioctl for device in /.../test.php on line 2
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67017&edit=1