variable-variables

Variable variable class extensions in PHP--is it possible?

Is something like the following possible in PHP? $blah = 'foo1'; class foo2 extends $blah { //... } class foo1 { //... } This gives an error. I want to dynamically set $blah so I can extend whatever class I want. Edit: The reason for wanting to do this because I wanted to use a function out of another class in a related cl...

How would I call a method from a class with a variable?

Given this class: class Tacobell{ public function order_taco(){ echo "3 Tacos, thank you."; } public function order_burrito(){ echo "Cheesy bean and rice, please"; } } $lunch = new Tacobell; $lunch->order_burrito(); $lunch->order_taco(); How would I do something like this? $myOrder = 'burrito'; $lunch->order_.$myOrder; ...

What is this loop using PHP $$ syntax doing?

I found this PHP code in an app I have to modify... $links = mysql_query($querystring); foreach (mysql_fetch_array($links) as $key=>$value) { $$key = $value; } I'm a bit stumped. Is it really iterating over the query results and copying the value into the key? If so, what would be the point of this? Also, what is the double $$...

How can I access methods based on strings in an array?

Hello! I'm not even sure if this is possible, but hopefully it is in Java. I know I've done it in PHP by using variable variables and accessing a variable dynamically, but I read this isn't possible in Java in a different question. I have an array of strings which contains the state of checkboxes in my JSF GUI. If all checkboxes are s...

PHP variable variables in .NET

Does .NET natively support anything similar to PHP's variable variables? If not, how1 could such a feature be most easily implemented? 1 If you think variable variables are always bad, feel free to state your case but the main question is: how can they be implemented? ...

How do I do Variable Variables in Python?

How do I accomplish this in Python? Here is an elaborative manual entry, for instance :http://us3.php.net/manual/en/language.variables.variable.php I hear this is a bad idea in general though, and it is a security hole in PHP. I'm curious if anyone knows how as well? ...

How can I use a variable variable in PHP?

Here is what I am trying to do: <?php $my_str = "My String"; $str = "%my_str"; $str = str_replace("%", "$", $str); echo $str; ?> The above code prints '$my_str' to the screen. But I want it to print 'My String', as in the actual value of the variable $my_str Anyone know how to do this? The reason I want this is bec...

Construct a PHP variable name based on other variable values and static text

I want to tell my function which variable to call based on the day of the week. The day of the week is stored in $s_day, and the variables I want to call changes based on which day it is. e.g. I've stored a string 'Welcome to the week' in $d_monday_text1. Rather than build a set of 7 conditional statements (e.g. if date=monday echo $fo...

Variable Variables Pointing to Arrays or Nested Objects

Hi, Is it possible to create a variable variable pointing to an array or to nested objects? The php docs specifically say you cannot point to SuperGlobals but its unclear (to me at least) if this applies to arrays in general. Here is my try at the array var var. // Array Example $arrayTest = array('value0', 'value1'); ...

Creating Variable Variables from MySQL Values

Is it possible to create a dynamic variable in PHP based on the value that comes from mysql database? I mean, say I have a field in mysql State When I read the value in php using row['State'] from the database and if I get a value like Alabama, I want to have a variable created like $Alabama_count and I will initialize to 0 or 1. Tha...

How can I simplify this redundant code?

Can someone please help me simpling this redundant piece of code? if (isset($to) === true) { if (is_string($to) === true) { $to = explode(',', $to); } $to = array_filter(filter_var_array(preg_replace('~[<>]|%0[ab]|[[:cntrl:]]~i', '', $to), FILTER_VALIDATE_EMAIL)); } if (isset($cc) === true) { if (is_string(...

php get the variable name from other variable

look at this simple script please $c1 = $_GET[c1]; $c2 = $_GET[c2]; $c3 = $_GET[c3]; $c4 = $_GET[c4]; $c5 = $_GET[c5]; for($i = 1;$i <=5;$i++) { echo $c{$i};//or something else here :/ } how can i print tha values of variables? Thanks ...

what's an actual use of variable variables?

Variable variables seem pretty cool, but I can't think of a scenario where one would actually use them in a production environment. Have you done so? How did you use them? ...

Variable variables: when useful?

Possible Duplicate: what's an actual use of variable variables? Ok, this question may look a little bit point-whoreish but i'd really like to know: when variable variables are useful? I'm programming in PHP for several years but i've never used them. For me it looks rather funny than useful. Can you provide some real life exa...

variable-variables in PHP

I know you can do: $hash('foo') and $$foo and also $bar[$foo], what are each of these things called? ...

How to check if a string can be used as a variable name in PHP?

In PHP one can use variable variables... For example... class obj { } $fieldName = "Surname"; $object = new obj(); $object->Name = "John"; $object->$fieldName = "Doe"; echo "{$object->Name} {$object->Surname}"; // This echoes "John Doe". However, $fieldName string may contain some characters not allowed in variable names. PHP will s...

javascript equivalent of php $$ dollar dollar

Hi, I have declared a local variable named cont in a function named validate. I am calling a function process from inside validate. I am sending the string 'cont' as argument to validate function. In the process function using the string 'cont' i want to access the javascript local variable's value like window['cont']. But i get undefi...

Access Variable variables with an object

Hello, I don't really know how to decribe this problem, so I'm sorry if the title is a bit unclear. I got an object with array fields. I got the name of these fields stored in a variable and I want to reach an element in one of those array fields. e.g. $field_name = 'array_field'; $object = new stdClass(); $object->array_field= array...

what happens when $$[object name] is declared

i trying to debug a php script and came across a declaration like $cart = new form; $$cart = $cart->function(); ...

Howto make a var. name with a var. in C/C++?

Hi, i have some vars live: int foo1; int foo2; .. and i want to reach them from: for (int i = 1;i<=2;i++) { // howto get foo1 and foo2? } how to get them? EDIT, end what when it will be no int but a Opject *pointer;? ...