473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

PHP Notice: Undefined variable: array_var

I have a class with an empty array like so:

private $detail = array();


Then I have a function later on in the class:

function get_array_value()
{
$detail_info = ' ';
foreach($detail as $key=>$value)
{
$detail_info .= CreateDetailEntry($value);
}
}

when I create an instance of my class and try to use the function get_array_value, I get this:

PHP Notice: Undefined variable: detail in blah blah file line ??

Is there a problem with creating an empty array that gets filled in later?
Apr 12 '07 #1
4 7302
I have a class with an empty array like so:

private $detail = array();


Then I have a function later on in the class:

function get_array_value()
{
$detail_info = ' ';
foreach($detail as $key=>$value)
{
$detail_info .= CreateDetailEntry($value);
}
}

when I create an instance of my class and try to use the function get_array_value, I get this:

PHP Notice: Undefined variable: detail in blah blah file line ??

Is there a problem with creating an empty array that gets filled in later?
--------------------------------------
I have tried declaring it public with the same result.
I tried creating it as private $detail = array(3); with the same result

What am I missing?
Apr 12 '07 #2
--------------------------------------
I have tried declaring it public with the same result.
I tried creating it as private $detail = array(3); with the same result

What am I missing?


changed it again: public $detail = array(1 => 'A');

same result. I have other arrays that work fine.
Apr 12 '07 #3
changed it again: public $detail = array(1 => 'A');

same result. I have other arrays that work fine.


Here is the rest of the error: "PHP Warning: Invalid argument supplied for foreach()", meaning the array I created.
Apr 12 '07 #4
code green
1,726 Expert 1GB
The $detail you are using in your function is local only to that function. To use a class variable you need to tell the class you are using the variable.
[PHP]$this->detail;[/PHP]
Apr 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mike | last post by:
I'm new to PHP - moving over from ASP. I have a number of include files, the first of which sets the value of a variable $loginmsg. I use that variable in a subsequent include file, but get a...
1
by: prabhunew2005 | last post by:
hi I am doing web portal design using php. I gave part of one of my screen coding. <html> <head> <script language = "javascript"> function list_all_click()
3
by: printline | last post by:
Can anyone help me with why i am getting this error message: Notice: Undefined variable: SalesRepID in C:\Inetpub\wwwroot\index.php on line 158 Here is my php code: <?php session_start();...
2
by: norwichchris | last post by:
hi, I am having serious trouble with my PHP Postcard script. The error message i get is: Notice: Undefined index: Notice: Undefined variable Basically it does not send out the scripts at...
1
by: bob johnson | last post by:
Notice: Undefined variable: db_host in C:\wamp\www\cbmall\index.php on line 7 Notice: Undefined variable: db_user in C:\wamp\www\cbmall\index.php on line 7 Notice: Undefined variable: db_pass...
1
by: mark anthony | last post by:
<?php mysql_connect('localhost','root','')or die(mysql_error()); mysql_select_db('goldas')or die(mysql_error()); if(isset($_POST)) { $a1 = $_POST; $a2 = $_POST; $a3 = $_POST;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.