|  | Posted by Ramon on 06/14/06 08:53 
Thanks Tony for your explanation,
 but I don't think I understand your solution. The getOuterHTML method
 expects no parameters. This is the error I get: "Call to a member function
 on a non-object". Did you mean that I have to adjust the getOuterHTML method
 in any way?
 
 This is my code (in short):
 
 <?
 
 class TextBox {
 var $m_sID;
 var $m_sName;
 var $m_sValue;
 
 // Class Constructor:
 function TextBox ($sID, $sName, $sValue) {
 $this->m_sID = $sID;
 $this->m_sName = $sName;
 $this->m_sValue = $sValue;
 }
 
 function getID() {
 return $this->m_sID;
 }
 
 function getOuterHTML () {
 return "<input type='text' name='" . $this->m_sName . "' value=' .
 $this->m_sValue . '>";
 {
 
 }
 
 class HTMLForm {
 var $m_oTextBoxes = array();
 
 function addTextBox($oTextBox) {
 $this->m_oTextBoxes[$oTextBox->getID()] = $oTextBox;
 }
 
 function getTextBoxByID ($sID) {
 return ($this->m_oTextBoxes[$sID]);
 }
 }
 
 $oTxtNumber = new TextBox ("Nr", "Number", "123");
 $oForm->addTextBox ($oTxtNumber);
 
 echo $oForm->getTextBoxByID("Nr")->getOuterHTML();
 
 ?>
 
 
 "Tony Marston" <tony@NOSPAM.demon.co.uk> wrote in message
 news:e6ogua$pti$1$8302bc10@news.demon.co.uk...
 > What you are describing is not a subclass but a contained object. A
 > subclass inherits from a superclass whereas you are instantiating an
 > object from within another object. There is a difference.
 >
 > What you want is this...
 >
 > $oForm->getTextBoxByID->getOuterHTML("Number");
 >
 > --
 > Tony Marston
 > http://www.tonymarston.net
 > http://www.radicore.org
 >
 >
 > "Ramon" <itsramon@zonnet.nl> wrote in message
 > news:448fc280$0$31637$e4fe514c@news.xs4all.nl...
 >> Hello
 >>
 >> I'm new to OOP in PHP and I have this question:
 >>
 >> I have a class called "Form", which contains a collection of classes
 >> (objects) called "Textbox".
 >> Now I need to call the Textbox class's method "getOuterHTML()".
 >>
 >> In Visual Basic, you should do it like this:
 >> oForm.getTextBoxByID("Number").getOuterHTML()
 >>
 >> In PHP I tried this: $oForm->getTextBoxByID("Number")->getOuterHTML();
 >> But that doesn't work...
 >>
 >> Is there a way to do this in one statement? (I use PHP4).
 >>
 >>
 >> Thanks in advance!
 >> Ramon.
 >>
 >
 >
 [Back to original message] |