php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67017 include_once() in if statement is taking incorrect parameter
Submitted: 2014-04-04 07:07 UTC Modified: 2014-04-04 17:34 UTC
From: seufert at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.6.0alpha3 OS: Mac OS/X 10.9
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: seufert at gmail dot com
New email:
PHP Version: OS:

 

 [2014-04-04 07:07 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-04 09:47 UTC] william75 at yopmail dot com
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.
 [2014-04-04 17:34 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-04-04 17:34 UTC] requinix@php.net
^ That.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 21:00:01 2026 UTC