php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42639 include in if-expression problem
Submitted: 2007-09-12 08:44 UTC Modified: 2007-09-13 09:49 UTC
From: koraktor at web dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.4 OS: Windows XP SP2
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: koraktor at web dot de
New email:
PHP Version: OS:

 

 [2007-09-12 08:44 UTC] koraktor at web dot de
Description:
------------
Included code in an if-expression is only available in the if-branch not the if-expression itself.

Reproduce code:
---------------
if(file_exists("code_to_include.php")
&& include("code_to_include.php")
&& check_included_code())
{
  task();
}

Expected result:
----------------
Included code from "code_to_include.php" should be accessible in check_included_code() and anything afterwards.

Actual result:
--------------
Included code from "code_to_include.php" is accessible in task(), but not in check_included_code().

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-12 11:07 UTC] jani@php.net
You do realize that include is a language construct and not a regular function? Please provide short but _complete_ example script which shows the problem clearly.
 [2007-09-12 12:48 UTC] koraktor at web dot de
Yes, I know that include is a language construct. But in fact, while writing a small example, I realized that there is another problem...

While my original code complains about a missing class (which should have been included), this simple test code causes the following error: "Failed opening '' for inclusion". IMHO this hints that the parser neglects a strict syntax check for this construction. The closing bracket of the if-expression seems to "start" the include, while binary and (&&) does not. So this bug seems to be associated with #28845 - which is fixed.

e.g.
if((include("code_to_include.php")) && ...) works.

But my syntax should either throw a syntax error (instead of an inclusion error) or it should be understood by the parser.
 [2007-09-13 09:49 UTC] jani@php.net
Expected behaviour: http://www.php.net/include/ (example 16.8)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Aug 15 18:00:02 2025 UTC