PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I find that completely useless, since you can just as well put the stuff from Step 5 into an array with the name of the input field as the key. It's a lot more elegant and easier to understand.
I find that completely useless, since you can just as well put the stuff from Step 5 into an array with the name of the input field as the key. It's a lot more elegant and easier to understand.
Hence I followed step 5 with "This is a rather trivial use of references". The point I was demonstrating was that you can use references to programmatically create variable names. Without going into quite long and detailed code it's tricky to come up with a useful example .. so I left it at something basic.
I find that completely useless, since you can just as well put the stuff from Step 5 into an array with the name of the input field as the key. It's a lot more elegant and easier to understand.
Without going into quite long and detailed code it's tricky to come up with a useful example .. so I left it at something basic.
Good point, but I still stand firm in my belief that variable variables are the devil incarnate . I'll just leave it at that, there's no point in going into another "OOP vs. Procedural" type of flamewar here.
foobar wrote:
I find that completely useless, since you can just as well put the stuff from Step 5 into an array with the name of the input field as the key. It's a lot more elegant and easier to understand.
Without going into quite long and detailed code it's tricky to come up with a useful example .. so I left it at something basic.
Good point, but I still stand firm in my belief that variable variables are the devil incarnate . I'll just leave it at that, there's no point in going into another "OOP vs. Procedural" type of flamewar here.
I agree with this completely. Variable variables I consider the devil aswell, as the programmer may become unsure as the where the variable came from. From what I can tell variable variables generally eliminate the need to manually declare the variables, much like extract().. but in those instances I find it much more clear to either have an array created of the related variables if it is already not an array you are working with.. or leave it as an array in the first place.
one place I find it useful is if you store configuration data in a database.. stuff like webmaster email, site name, etc whatever , in a database structure like index_id,name,value,description
then you can load it by a simple query in config like
and suddenly you have a configuration table where you can change settings on the fly via an admin panel, (a la phpBB) instead of having to manually edit and upload a configuration file (and the chances of a typo or extra whitespace causing your beautiful new website to blow up with ugly error messages all over the place just when you are getting the most traffic of your life.. how embarrassing..)
On a single page request a "config" variable does not need to be changed, by my definition, the only time a changing variable would be considered a config var to me is if the application was something like a shell script that runs 24/7. Think about it, in a traditional web application the only way a config variable would be changed, is the user changing the config variable, wether it be done in a seperate page request or through AJAX, one process changes the config variable in the database, the next process reads that config value out.
jshpro2 wrote:On a single page request a "config" variable does not need to be changed, by my definition, the only time a changing variable would be considered a config var to me is if the application was something like a shell script that runs 24/7. Think about it, in a traditional web application the only way a config variable would be changed, is the user changing the config variable, wether it be done in a seperate page request or through AJAX, one process changes the config variable in the database, the next process reads that config value out.
Interesting line of thought. To be honest, I never thought of it that way. Hmm.
If you really needed your 'config' vars to be editable at runtime, it's a more solid solution to use a master array for configs, as opposed to variable variables (which can lead to issues)
However define is probably the more practical solution since it's truly global!
Afterthought:
debugging = print_r($CONFIGURE);
Each approach has it's benefits, for instance a heirarchial config tree using the $CONFIGURE array multidemensionally, (ex. keep all mysql related directives in their own sub array)