By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

Function not returning expected value

P: n/a
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.

<SNIP FROM CALLING METHOD>

require_once BASE . '/config/formfields.inc.php'; // file with needed
arrays

// 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/formfields.inc.php'); // it's the right
file
}

</SNIP>

<SNIP FROM FILE WITH NEEDED ARRAYS>

<?php

require_once BASE . '/config/log.inc.php';

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

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

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

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

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

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

?>

</SNIP>

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
je**@cowz.com wrote:
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?


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


Jul 17 '05 #2

P: n/a
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....

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.