php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #37211 require_once: a statement or a function?
Submitted: 2006-04-26 17:04 UTC Modified: 2006-05-16 22:50 UTC
From: idbaxter at semdesigns dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: idbaxter at semdesigns dot com
New email:
PHP Version: OS:

 

 [2006-04-26 17:04 UTC] idbaxter at semdesigns dot com
Description:
------------
The online manual clearly states that require_once
(and related actions such as include) are *statements*.
There is no documented return value.
It also states that "if" is a *statement*.

But actual code sample (from a running
system) shows that require_once
(and related actions such as include) can
be used like a function (see attached code),
and even odder, the "@" operator can suppress
errors.

Now, you can't do that with "if" statement.
So, if require_once is a statement, you shouldn't
be able to do that.  If it is a function,
it should be documented as such.

So, is the following code wrong?

Reproduce code:
---------------
<?php
 
if (! require_once /* require_once as a function */(APP_ROOT_DIR.'EcWebFramework/conf/Includes.php')) {
            $msg = 'Can not load Includes - check filesystem.';
            error_log($msg);
            die($msg);
}

@include_once( $includePath ) ; /* @ supressess error */

if( !@include_once( $include_file ) ) / *both wierdnesses */
{
            $this->__errorAlert( 'TemplatePower Error: Couldn\'t include script [ '. $include_file .' ]!' );
            exit();
}

Expected result:
----------------
I expected to get a complaint about illegal syntax.

Actual result:
--------------
Above code runs without complaint.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-26 18:37 UTC] vrana@php.net
PHP manual definition of a statement: "A statement can be an assignment, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement)." require fits in this definition.
 [2006-05-16 22:45 UTC] idbaxter at semdesigns dot com
Your "technical" defintion of statement doesn't help.

The issue is,  can I use require_once and include_once
as functions inside the if condition clause?
I clearly cannot use a "if statement" inside that condition
clause.  Yet the sample code appears to treat
require_once etc. as *value* returning functions.

Are require_once and include_once value returning functions?
If so, what value do they return? (The docs imply that they do not, and therefore cannot be used in an expression context.)
I think there's two problems here:
1) what is the intended definition?
2) What does the documentation say?
 [2006-05-16 22:50 UTC] tony2001@php.net
Please leave it as is. 
include*() and require*() DO return values, if you didn't know, but that doesn't mean they are functions or can be used in expressions.

Read here: http://php.net/include 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 19 12:00:03 2025 UTC