Posted by Rik on 06/14/06 08:14
Ramon wrote:
> 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).
How does you object "contain" the textboxes, and how have you defined the
method getTextBoxByID?
I'm no real OOP programmer, but in this case I'd:
<?php
class B{
function display(){
echo "works";
}
}
class A{
var $bs = array();
function add(){
$this->bs[] = new B;
}
}
$a = new A;
$a->add();
$a->bs[0]->display();
?>
Grtz,
--
Rik Wasmus
[Back to original message]
|