PHP Array To Class Static Public Values.

Posted by what on Stack Overflow See other posts from Stack Overflow or by what
Published on 2010-03-28T02:41:07Z Indexed on 2010/03/28 2:43 UTC
Read the original article Hit count: 251

Filed under:
|

I want to make a class that has all the values of an array as a static object in that class. For example:

$vars=array(... );//some array with actual values
$Class_code='class MyClass{';

for($i=0; $i<count($vars); $i++){
    $Class_code.='static public $'.strval($vars[i]).';';
    }
eval($Class_code.'}');
/* When I echo the line above it says that the vars
for MyClass (MyClass::vars) are missing even with strval().
*/

So, how can I get $vars[i] to be a string if strval didn't work?

© Stack Overflow or respective owner

Related posts about php

Related posts about beginner