Object-Variables-0.9Object-Variables-0.9Object-Variables-0.9 07/30/2004 12:14 AM This is a GrokNews Entry: (what is grok?)Object-Variables-0.9Grok Headline matches for Object-Variables-0.9Object-Variables-0.5Object-Variables-0.5 07/27/2004 12:28 AM Object-Variables-0.4Object-Variables-0.4 07/25/2004 06:12 AM An Introduction to VariablesAn Introduction to Variables 11/27/2002 09:47 PM This is only for those who are new to php, or maybe programming altogether. This won't 'enlighten' you, or make you 'one with everything', but it should make you one with variables. PHP Application VariablesPHP Application Variables 07/02/2002 09:57 AM Application Variables in PHPApplication Variables in PHP 07/01/2002 08:29 AM This is the first article of several on developing an architecture for Enterprise PHP, where we are running dedicated PHP servers tuned to serve large number of web pages. This work originated in the need to save the current working database connection as an Application variable in a primary and fallback database server configuration. This can be extended to saving other configuration information that rarely changes... -- John Lim
"zeldman.jayne" Application Variables with PHPApplication Variables with PHP 08/05/2002 10:44 PM One of the most common feature requests that PHP developers ask for is application variables. These are variables that are globally available to all PHP scripts on a web server. There are currently several implementations. Variables and PathsVariables and Paths 06/26/2002 07:05 PM In this month's Q&A column, John Simpson answers questions about XSLT variables and XML document paths. Predefined VariablesPredefined Variables 06/09/2004 03:40 PM Variable Variables in PHPVariable Variables in PHP 12/19/2002 10:43 PM Variable Variables in PHP Well since it's late but I'm still grinding and I feel guilty for not blogging much today, here's a special PHP Treat: A Variable Variable Tutorial. Yes that's right. There is a feature in PHP called "Variable Variables". One of the issues that I had with implementing our Digibuy support was our old friend and enemy: Parsing. This is such a fundamental thing but there always seems to be a new wrinkle in it. In this case we had an existing PHP script which did our registration calculations and was expecting a certain set of variables. Now this code was fairly complex and I didn't want to re-write it (much). Here's the input data we had to parse: author_id=BillBrown & author_password=HemosRules & prod_sku=98079949999 With the exception that it had like 30 odd variables in it. Since my code was expecting a series of variables I needed to parse this and automatically create a series of variables like $author_id and $author_password. Now if this data was being given to me by a URL then it would be easy -- PHP could automatically do it or I could just pull them out of $_REQUEST. But, instead, I had them going to me as if they were a file. So ... How do you create a series of variables on the fly? Note: Yes I could have made an associative array but that wouldn't have taught me anything, now would it ? I could also have gotten a similar effect with the extract function but I found out about that after this working. And if the code is working then ... Well deep in the recesses of what I call a brain was a recollection of "variable variables". I think I heard about this in a talk that Rasmus gave although I can't honestly be sure. I do know that whenever you need to do "meta" type tasks like this in a language, you need to poke around the oddball features since that's usually where they reside. What I do is look for the sections of the documentation that I've never read. The idea behind a variable variable is simple: interpret the value of a variable and make it into a variable itself. I.e. the "variable variable" nomenclature. Since php uses $ for indicating a variable they've chosen to use $$ to make a variable variable. Let's say you have two variables, $part1 and $part2. If $part1 = "author_id" and $part2="HemosRules" how do I get to $author_id = "HemosRules". Simple: $$part1 = $part2. Yup. It's just that easy. Of course I did need to wrap it into a string parsing loop. Here's the guts of it: $strarray = explode("&",$input); foreach ($strarray as $stritem) { $stritem = trim($stritem); $part1 = substr ( $stritem, 0, strpos ( $stritem,"=" ) ); $part2 = substr ( $stritem, strpos ( $stritem,"=" )+1, strlen ( $stritem ) ); #magic! $$ is a "variable variable" i.e. it converts the value #in the variable into a variable itself $$part1 = $part2; } The way this works is an input string, $input, contains everything that needs to be processed. First I explode this into an array using "&" as the delimiter. Then I loop over the array with a foreach loop creating a $part1 variable and a $part2 variable. Finally I just do the magic $$part1 = $part2. Here's the example Source Code. Here's the working Example Thanks again to my favorite Systems Administrator, Apokalyptik, for showing me how to use PHP to generate code listings. Much easier than pasting it into a blog entry. More on Variable Variables from PHP.Net: [_Go_] Variable Variables. A little confusing but definitely a frothy good thing! Tunneling VariablesTunneling Variables 04/09/2004 04:09 PM In Bob DuCharme's latest Transforming XML column he explains the use and virtues of XSLT 2.0's tunneled variables. Using hash variables in PerlUsing hash variables in Perl 05/03/2004 09:19 AM CNET May 3 2004 1:48PM GMT Internal Variables for Use in Your
|
Also check out: |