Re: Problem referencing variables in objects
- From: George Mills <gmills@xxxxxxxxxxxxxxxxxxx>
- Date: Tue, 23 May 2006 01:45:51 GMT
Well, that was my best guess.
The only other thought I have is to test the variable right after you set it via $textinput=>_message and make sure that its there then.
Maybe the TextInput object goes out of scope somewhere between the call to validate and the call to render.
Regards.
Rob Dorn wrote:
I apologize George, I was not complete in my text..
I do use $this->_element and $this->_message in every case I reference the variables.
Rob
"George Mills" <gmills@xxxxxxxxxxxxxxxxxxx> schreef in bericht news:uVpcg.17249$Lg.7140@xxxxxxxxxxxxxxxxxxxxxxxxxxx
Rob Dorn wrote:
Hello all.
I have an urgent problem building a small form processing system.and hope somebody out
there can help me?
I have a form class which contains severals elements of the type input text (created by the
TextInput class). These element classes are added to the $_elements array that acts as an
object stack (see pseudo code below).
The render() function of the form will loop through the $_elements stack and calls the render()
functions of each element. This element render() function will return the html and will finally
build the complete page.
This method workt fine, so I would like to do the same with the validate function. This also work
as expected, except for one thing:
When the validation of a text input element failes I fill a class variable called $_message. This
messages should be rendered (displayed) in the "div" element containing the input text element.
However this is not the case. The message is set and known in the validate() function but not in
the render() function which is called some time later.
So what am I doing wrong? Is this a problem of the variable scope, or the wrong way to reference
objects or variables? Can somebody please give me hint?
class Form
{
var $_elements = array();
function render()
{
// render every element in the form $_elements array (return the html sting)
}
function validate()
{
// call the validate() function of every element in the form $_elements array
}
}
class TextInput
{
var $_message;
function render()
{
// render this element (return the html sting)
// if a $_message is set (by the validate function) render it into the html output
}
function validate()
{
// see if the value of this element is valid; if not set the $_message variable
}
}
You asked for a hint not the solution so I hope I don't give too much away. :)
In validate and render are you referring to $this->_message or $_message? $this->_message is the class's variable, $_message is the function's variable.
- References:
- Problem referencing variables in objects
- From: Rob Dorn
- Re: Problem referencing variables in objects
- From: George Mills
- Re: Problem referencing variables in objects
- From: Rob Dorn
- Problem referencing variables in objects
- Prev by Date: Re: PHP_SELF in Buttonproblem in PHP5
- Next by Date: Re: HTML Email Form - PLEASE HELP!!!
- Previous by thread: Re: Problem referencing variables in objects
- Index(es):