Is it possible to create nested classes in PHP as it is in C#?

Posted by Edward Tanguay on Stack Overflow See other posts from Stack Overflow or by Edward Tanguay
Published on 2011-01-14T11:10:38Z Indexed on 2011/01/14 11:53 UTC
Read the original article Hit count: 222

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about php