note 43414 added to language.oop
| From: | eparker at freeshell dot org | Date: | Sun, 20 Jun 2004 20:56:49 +0000 |
| Subject: | note 43414 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-71411@lists.php.net to get a copy of this message | ||
Bad news sports fans! PHP (4, at least) doesn't support nested classes. Or at least so I found.
One way I found of deaing with this is to use a "factory" pattern, if you need to
associate two things together. This wa you can tie them together - it's a little bit messier,
but it works:
class IShouldBeAnInternalClass
{
var $associatedExternalClass;
function IShouldBeAnInternalClass($externalClass)
{
$this->$associatedExternalClass = $externalClass;
print "In Internal Class Constructor!";
}
}
class ExternalClass
{
function ExternalClass()
{
print "In external class constructor!";
}
function ProvideInternalClass()
{
return new IShouldBeAnInternalClass($this);
}
}
This will let you provide as many internal classes as you want, and they can still have access to
the 'external' classes methods, and internals. Still would be nice to just be able to have
an internal class, mais oui?
----
Manual Page -- http://www.php.net/manual/en/language.oop.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43414
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43414&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43414&report=yes
Search -- http://master.php.net/manage/user-notes.php