note 43414 deleted from language.oop by aidan
| From: | aidan@php.net | Date: | Sat, 03 Jul 2004 14:44:41 +0000 |
| Subject: | note 43414 deleted from language.oop by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72430@lists.php.net to get a copy of this message | ||
Note Submitter: eparker@freeshell.org
----
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?