Posted by David Haynes on 04/18/06 02:04
Jerry Stuckle wrote:
> Wescotte wrote:
>> Sure, but I prefer to find a method that allows for virtually no
>> modification to the original code.
>>
>> I do prefer to use the method David suggested. I wasn't aware I could
>> do something like $new_class = new $class_name_string;
>>
>> I'd also like to thank you guys for all the help
>>
>
> The only problem might be - I don't know if you can do it directly. You
> may have to do something like
>
> $myObject = eval(new $className);
>
> Never tried it either way, though.
>
This seems to work as expected:
<?php
class A {
function ident() {
echo "This is class A\n";
}
}
class B {
function ident() {
echo "This is class B\n";
}
}
$classes = array('A', 'B');
foreach( $classes as $class ) {
$obj = new $class();
$obj->ident();
}
?>
-david-
[Back to original message]
|