Re: Variable Variable Array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Evert|Rooftop Solutions wrote:
Ryan Jameson (USA) wrote:

I've been using "variable variables" for years with PHP.

I'm not really sure this is really good practice. Sure, php allows it but I think you should try to avoid them.
[snip]
It's excellent practice to use dynamic variables* when you need them. There are simply no practical ways around them in many cases, and they can make cleaner and shorter code in many many places.


For truly dynamic pieces of code, there's really just no other way (creating an arbitrary class object for an arbitrary database table and calling common methods (e.g. validate_data(), add()) on said classes.

Of course, when you're doing things like this, you need to make sure you're sanity checking your data that much more, as you can get into namespace issues if you aren't careful.

but if you're careful, you can get fun scary things like this!

	$this->{$this->form} = new $this->form;

or this!

$this->result[$table_name][$view_name] = ${"{$table_name}{$view_name}"}->add($view_data);

... be sure to comment your code :)

* Note: I call them dynamic variables, I have no clue if that's the 'accepted' term for them. Makes sense to me, though.

cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux