I am having a strange issue with getting an array returned from an include. The example taken from the manual shows the behavior I am expecting:
return.php
<?php
$var = 'PHP';
return $var;
?>
noreturn.php
<?php
$var = 'PHP';
?>
testreturns.php
<?php
$foo = include 'return.php';
// This is the expected behavior.
echo $foo; // prints 'PHP'
$bar = include 'noreturn.php';
echo $bar; // prints 1
?>
My usage scnario gives different result. I load Zend_Config by calling it with a simple include that returns an array() :
config.php
<?php
/*
* Configuration options loaded in Zend_Config
*/
return array(
'localDB' => array('serverName' => 'TESTDB',
'uid' => 'TESTUSER',
'pwd' => 'TESTPW',
'DB' => 'TESTDB'
),
);
// in the app I can call Zend_config somewhat like this ...
$configfile = 'config.php';
// zend_config takes an array as parameter, returned by the included file...
$config = Zend_config(include $config);
All is fine. Except now I want to overide this array for test configuration, without changing the file, so I do this:
testConfig.php
$testsettings = include_once 'config.php';
// override the array
$testsettings['localDB']['serverName'] = "TEST";
//return the overriden array
return $testsettings;
Now, the weird part. It all works fine when I execute php -f testConfig.php and var_dump() $testsettings.
But if I include this file in a testcase to have orverriden settings value, the result is always a (bool) true, like the example include shown at top with no return value set.
I have thought of a few workarounds for this, but was wondering out of curiosity if anyone had a clue as to why it does this.
include_oncereturnstrueevery time after the first one. So the linesets
$testsettingsto true if you’ve includedconfig.phpanywhere in earlier code.