Is it possible to create nested classes in PHP as it is in C#?
- by Edward Tanguay
In C# you can have nested classes like this, which are useful if you have classes which do not have meaning outside the scope of one particular class, e.g. in a factory pattern:
public abstract class BankAccount
{
private BankAccount() {}
private sealed class SavingsAccount : BankAccount { ... }
private sealed class CheckingAccount : BankAccount { ... }
public BankAccount MakeSavingAccount() { ... }
public BankAccount MakeCheckingAccount() { ... }
}
Is this possible in PHP?
I've read that it was planned for PHP 5, then cancelled, then planned again, but can't find definitive info.
Does anyone know how to create nested classes (classes within the scope of another class) as in the above C# example using PHP 5.3?