473,383 Members | 1,829 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,383 software developers and data experts.

array datatype problem

Hello, I'm attempting to create class in PHP that basically manages a
two seperate arrays. However, when I attempt to add a new element to
the array, the array itself converts to the datatype of the element I'm
attempting to add instead of being an array.

I am probably overlooking something very obvious, but here is my code.
The conversion takes place on this line:

$this->$dError[$sKey] = true;

in the method

addError($sKey, $sMessage)

Here is my source for the class:

class FormErrors {
var $dError;
var $dMessage;
var $errTxtClass;
var $errTxtLeft;
var $errTxtRight;

function FormErrors(){
$this->$dError = array(0 => true);
$this->$dMessage = array(0 => true);
}

function addError($sKey, $sMessage){
if(array_key_exists($sKey, $this->$dError)){
$this->$dMessage[$sKey] = $sMessage;
}else{
$this->$dError[$sKey] = true;
$this->$dMessage[$sKey] = $sMessage;
}

}

function isKeyValid($sKey){
$bValid = true;
if(!array_key_exists($sKey,$this->$dError)){
$bValid = false;
}
return $bValid;
}

function isValid(){
$bValid = true;
foreach($this->$dError as $sKey => $bValue){
if($bValue){
$bValid = false;
}
}
return $bValid;
}

function printErrors(){
foreach($this->$dError as $sKey => $bValue){
if($bValue){
echo $sKey."<br>";
}
}
}
}

Jul 17 '05 #1
2 1268
Mike wrote:
Hello, I'm attempting to create class in PHP that basically manages a
two seperate arrays. However, when I attempt to add a new element to
the array, the array itself converts to the datatype of the element
I'm attempting to add instead of being an array.

I am probably overlooking something very obvious, but here is my code.
The conversion takes place on this line:

$this->$dError[$sKey] = true;


Class properties should be addressed like:

$this->property, not as $this->$property

So the above line becomes:

$this->dError[$sKey] = true;
Apply this modification throughout your code.
JW

Jul 17 '05 #2
JW,
Thanks for the help!

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Powell | last post by:
if (is_array($_POST)) { foreach ($this->getAssocSectionsObjArray($key, $dbAP) as $obj) { print_r($obj); print_r(" in array? "); print_r(in_array($obj, $result)); print_r("<P>"); if...
1
by: OlgaM | last post by:
Hello, i'm trying to initialize an array. The class List contains this in its private data members: ListNode<DATATYPE> *dataItems; In the constructor, i'm trying to allocate space for...
1
by: Raptor | last post by:
Hi, I'm quite new to MySQL and quite impressed by its feature set. I've also been looking at Interbase and it has a feature that allows a multidimensional array to be stored in a single field. ...
4
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving...
11
by: Magix | last post by:
Hi, what is wrong with following code ? typedef struct { word payLen; datatype data; } msg_type;
2
by: garak | last post by:
Hi, I want to add one element to an Array dynamicly, according to the type of the parameter ALLDATA. ALLDATA may be of type PObjects, PActions, PMaterials. I Thougth about my code to look...
2
by: XML newbie: Urgent pls help! | last post by:
Hi, I am getting the error: Value of type 'String' cannot be converted to '1-dimensional array of Long'. in the following line for TextBox2.Text field : ...
8
by: Sam | last post by:
I have a situation occuring in my code and I just can't see to figure out why I have an structure called employee that will put all of the employee id's into a char array set to 10 struct...
1
by: Freelancer Deepak | last post by:
hi friends i have a problem i have written a code for accepting table name , feld names and datatype from user and i want to create a table in database . my problem is that i am auable to create a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.