Including PHP in weird with multiple inclusion
I have the following code:
if (include_once(dirname(__FILE__).'/file.php')
|| include_once(dirname(__FILE__).'/local/file.php')
)
{
This raises an error as PHP is trying to include "1"
(presumably dirname(__FILE__).'/file.php' || dirname(__FILE__).'/local/file.php'
)
By commenting out the second line, this job works as intended, except it won't use the second file. Do I really need to use elseif
and duplicate the code here, or is there a way to get this to work?
$ php --version
PHP 5.2.6-3ubuntu4.2 with Suhosin-Patch 0.9.6.2 (cli) (built: Aug 21 2009 19:14:44)
Copyright (c) 1997-2008 PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
source to share
Group operators include
:
if ( (include_once dirname(__FILE__).'/file.php')
||
(include_once dirname(__FILE__).'/local/file.php')
)
See example # 4 on the man page:
<?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';
}
?>
source to share