Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5957089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:21:04+00:00 2026-05-22T18:21:04+00:00

I am having a strange issue with getting an array returned from an include.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:21:05+00:00Added an answer on May 22, 2026 at 6:21 pm

    include_once returns true every time after the first one. So the line

    $testsettings = include_once 'config.php';
    

    sets $testsettings to true if you’ve included config.php anywhere in earlier code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a strange issue with getting my GridView - RowDataBound method to compile.
I am currently having a strange issue with an application migrated from rails 2.3.8
I'm currently having a strange issue whereby all browsers except from Google Chrome are
Having a strange issue with some C# code - the Getter method for a
I am having a strange DB2 issue when I run DBUnit tests. My DBUnit
I am having a very strange behavior in JBoss, and I'd like avail myself
I'm having a strange issue where a custom control I've built for the iPhone
Having a strange issue in IE7. In a number of spots, I have a
Having a strange issue with the TabContainer in the AJAX Toolkit. We have several
I am having a strange issue opening up my UserControl in Expression Blend when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.