Function not returning expected value

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a php file that contains a couple of arrays used for
state/country pull-down lists. I have two global arrays and an accessor
method for each. I have some simple logging methods, so I know a little
bit about what I'm getting back. When I try to get the arrays from
another file using the accessor methods, I get no array back. Within
the file that contains the arrays, I can access them by global name and
also by the accessor methods. Any ideas why I cannot access the arrays
from another file? Code below.


require_once BASE . '/config/'; // file with needed

// the calling method
function display_states($smarty){

    logobj(function_exists(get_states));          // returning True/1
    $s = get_states();
    logobj($s);                                   // no love here
    logobj(BASE . '/config/');  // it's the right




require_once BASE . '/config/';

$states = array('Alaska',
    'California');  // etc., etc.

$countries = array('United States',
    'Albania');    // etc., etc.

logobj($states);       // looks good
logobj($countries);    // looks good

 * get_states
 * Fetches a list of states.
function get_states(){
    global $states;

 * get_countries
 * Fetches a list of countries.
function get_countries(){
    global $countries;

logobj(get_states());     // looks good
logobj(get_countries());  // looks good



Re: Function not returning expected value wrote:
Quoted text here. Click to load it

IMO, the only possible explanation is that the $states array gets redefined
as a scalar somewhere down the line...



Re: Function not returning expected value

That's a good point. I use a "smarty" template, and when I look at the
contents I see this in the member variables:

    [_tpl_vars] => Array
            [SCRIPT_NAME] => /drc2/register.php
            [states] =>
            [countries] =>

Could an eval statement be creating the "states" var here and
clobbering my initial states reference?

I will experiment and post my results....

Site Timeline