PHP: Instantiating a class from a variable oddly fails
问题 I'm trying to instantiate a class (a Laravel3 Eloquent model) by a variable, and I'm getting an error saying that the class is not found. When I hardcode the class name, though, it works just fine. (FYI, in the code below $contact_type is expected to either be Phone, Fax, or Email.) Here's what I'm playing with at the moment: foreach( $input AS $contact_type => $contact_info ) { foreach( $contact_info AS $data ) { $obj = new $contact_type( (array)$data); echo'<pre>Obj: ',print_r($obj),'</pre>