Home arrow PHP arrow Page 6 - Using Variable Variables in PHP

The Never-ending Variable - PHP

Quite possibly one of PHP’s least utilized yet most valuable features is its support for Variable Variables. In short these are a method of using the value of one variable to call the name of another. Sound confusing? We'll explain everything...

TABLE OF CONTENTS:
  1. Using Variable Variables in PHP
  2. Variable Variables?
  3. Using Variable Variables with Arrays
  4. Variable Variables with Functions
  5. Variable Variables with Classes
  6. The Never-ending Variable
  7. Conclusion
By: Eric Seufert
Rating: starstarstarstarstar / 15
February 14, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Another interesting quirk about variable variables is that they are seemingly infinite. The following code works just fine to produce "The Great Thing About Variable Variables Is They Never End!":

$x = "The"; $$x = "Great"; $$$x = "Thing"; $$$$x = "About"; $$$$$x = "Variable"; $$$$$$x = "Variables"; $$$$$$$x = "Is"; $$$$$$$$x = "They"; $$$$$$$$$x = "Never"; $$$$$$$$$$x = "End!"; echo "$x ${$x} ${${$x}} ${${${$x}}} ${${${${$x}}}} ${${${${${$x}}}}} ${${${${${${$x}}}}}} ${${${${${${${$x}}}}}}} ${${${${${${${${$x}}}}}}}} ${${${${${${${${${$x}}}}}}}}}";




 
 
>>> More PHP Articles          >>> More By Eric Seufert
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap

Dev Shed Tutorial Topics: