473,654 Members | 3,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function not returning expected value

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_sta tes)); // 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($countri es); // 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($countri es);
}

logobj(get_stat es()); // looks good
logobj(get_coun tries()); // looks good

?>

</SNIP>

Jul 17 '05 #1
2 1952
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1864
by: lawrence | last post by:
Here I have two functions, the first returning a value to the second. When I put print_r() on the last line of the first function, I can see that the correct values are in the array as expected. But when I put print_r() in the second function, around the array supposedly returned from the first function. I get nothing. What should I look for?
14
1872
by: lutorm | last post by:
Hi, I'm having a problem with a return statement being parsed to return a function (I think). Check here: template <typename T> class A {}; template <typename T> class maker_of_A { public: A<T>& make_A() {return A<T>();}; };
5
4100
by: Andy Sutorius | last post by:
Hi, I am attempting to convert this vb function to csharp but I am getting stuck on the if statement dt.Rows(iLoop)("FAQCategoryID")). The compiler says "method name expected" and underlines dt.Rows. I don't understand. Thanks for your help. Function GetSelIndex(CatID as String) as Integer Dim iLoop as Integer
6
7606
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards, Karthi
89
6034
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be used." Could anybody tell me why gets() function is dangerous?? Thank you very much. Cuthbert
3
2716
by: ali | last post by:
Hi, When I pass a pointer as an argument of a method, is it safe if I change the data pointed by the argument and return it upon completion ? For example: Object* someFunction(Object* ob) {
7
2401
by: arnuld | last post by:
/* C++ Primer - 4/e * * 1st example from section 7.2.2, page 234 * returning 2 values from a function * * STATEMENT: * to find a specific value in a vector and number of times * that value occurs in th vector. */
1
1425
by: J. Frank Parnell | last post by:
arrrrrg: Condo for rent has 3 price tiers (for different times of the year): value regular premium For every 7 nites they stay, they get 1 free, and that free one should be the cheapest night (1 value nite, 6 premium nites, they should get the value nite free)
26
4850
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure about the syntax of calling the same. #include <stdio.h> void fp1()
160
5826
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.