Page 1 of 1

Dynamic Vars with spaces...

Posted: Mon Nov 07, 2005 5:51 pm
by Tsukassa
Maybe you guys will laugh at me, but I thought I would be able to create my vars directly from the my mysql data base, here is the script :

Code: Select all

for($k=0;$k<count($keys);$k++){
				$this->$keys[$k]=$myItem[$keys[$k]];
			}
At first it seem a great idea, but as you guys probably figured out, some of my keys[$k] contains space. It works, even if the var name has a space, but I wanted to know if there was a way to access it... a var you can't access isnt really useful you know...

by the way, its my first post, and its not going to be my last! :)

Posted: Mon Nov 07, 2005 7:41 pm
by feyd
technically, there is a way to access it, but it's far easier to deal with them if they don't have illegal characters in them.. basically anything that isn't alphanumeric or an underscore should be stripped out..

Posted: Mon Nov 07, 2005 7:59 pm
by Tsukassa
fine, I'll use normal vars, but I'm curious you see, how could I access those vars?

Posted: Mon Nov 07, 2005 8:06 pm
by feyd

Code: Select all

[feyd@work]>php -r "$a = new stdClass; $a->{'some var'} = 'twins!'; var_export($a);"
class stdClass {
  public $some var = 'twins!';
}

Posted: Mon Nov 07, 2005 8:09 pm
by Tsukassa
Thanks for your fast response :)