Reply to Re: Problems with include and duplication function definitions

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация