This is a discussion on question regarding subclasses, is this possible to do within the PHP General forums, part of the PHP Programming Forums category; Hi, i was wondering if the last line of the following code is possible somehow (the second last works perfect) ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi, i was wondering if the last line of the following code is possible
somehow (the second last works perfect) but say i wanted to automatically get the id (or anything else for that particular window) would it be possible? or would i have to include a new function in windows called setID or something like that? ----------------php code----------------------------- <?php class house{ var $windows; function house(){ $this->windows = new windows(); } function getSize(){ return "Big House"; } } class windows{ var $id; function windows($id = "all"){ $this->id = $id; } function showID(){ echo "<br>ID: " . $this->id; } } $test = new house(); echo $test->getSize() . "<br>\n\n"; $test->windows->showID(); $test->windows("Window3")->showID(); ?> -------------------end php code-------------- I could always have $test->windows->setID($id) then display the properties for that current window, but it would be sumpler if i could use $test->windows($id)->showID() and if no var is there, show all...any ideas on how to do this? Thanks heaps Luke |
|
|||
|
* Thus wrote Luke (webmaster@build3d.com.au):
> > $test->windows->showID(); > $test->windows("Window3")->showID(); > ?> > -------------------end php code-------------- You might want to read: http://php.net/oop Curt -- If eval() is the answer, you're almost certainly asking the wrong question. -- Rasmus Lerdorf, BDFL of PHP |