Dynamic Class Name Assignments
| From: | bob pilly | Date: | Wed, 24 Nov 2004 11:51:51 +0000 |
| Subject: | Dynamic Class Name Assignments | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-202749@lists.php.net to get a copy of this message | ||
Hi All, im new to classes in PHP. Im trying to create
several instances of a very basic class but i want
each name to be based on number values in an array and
im not sure if it is allowed and if so how to do it. I
assume that im not allow to have a var starting with a
number so what i am trying to do is add the word case
to the front of the class instance name so i would
have $case100,$case101 etc. Im am using PHP 5.02.
Heres my code
<?php
class Test
{
//members
var $caseid,$fee;
function Test($caseid){
$this->caseid=$caseid;
}
function addmember($membername,$value){
$this->$membername=$value;
}
}
$names=array("100","101","102","104");
$numnames=count($names);
for($i=0;$i<$numnames;$i++){
*** below is the syntax im missing ***
$case.$names[$i] = new Test($names[$i]);
}
var_dump($case100);
?>
Thanks for any help in advance!
Cheers
Bob Pilford
___________________________________________________________
ALL-NEW Yahoo! Messenger - all new features - even more fun! http://uk.messenger.yahoo.com