This works if you know the name of the class. What I'm looking for is a way to 
get one of the sub classes and initialize it dynamically. 

From: David Otton <>
To: Raymond Irving <>
Cc: PHP-General List <>
Sent: Sun, October 25, 2009 10:25:27 AM
Subject: Re: [PHP] How to Get the Sub Classes of a Parent Class

2009/10/25 Raymond Irving <>:

> I want to automatically initialize a specific sub class when the php page is 
> loaded.
> I'm looking for a solution for php 5.1+ or anything that's optimized for 5.3

You may be able solve this with a simple class_exists() (pseudo-code ahead):

if(class_exists($var)) {
    $class = new $var;
} else {
    $class = new FourOhFour;

Reply via email to