Questions tagged [variable-variables]

Language feature of PHP: A variable variable takes the value of a variable and treats that as the name of a variable.

Language feature of PHP: A variable variable takes the value of a variable and treats that as the name of a variable.

171 questions
0
votes
2 answers

How to use variable variables in class variables and function arguments

This is what I want to do: class Contacts { private $_plural = 'contacts'; private $_single = 'contact'; private $_factory = 'contactfactory'; private $_model = 'contact_model'; private $_idname = $_plural . "Id"; function…
Angelo A
  • 2,744
  • 6
  • 28
  • 37
0
votes
2 answers

PHP Variable Variable Request Method

I'm working on a web library for personal use. I thought I'd be all clever and use variable variables to make my library support all request methods easily. I had: $request = '_' . $_SERVER['REQUEST_METHOD']; $request = $$request; But I…
csga5000
  • 4,062
  • 4
  • 39
  • 52
0
votes
1 answer

How can I late static binding in inherited class with variable variables of PHP

The thing is, suppose we have three classes A, B and C. B and C inherit from A.
0
votes
1 answer

Variable variables for use in Element Tree Python

I'm creating an XML DOM using python's Elementtree module, and it seems that it uses variables as nodes. My question is, how do I create unique varible names so that the nodes are persistent for the DOM if I'm adding records to the DOM in a loop.…
Jacksgrin
  • 85
  • 1
  • 11
0
votes
6 answers

PHP variable variables getting array value

I'm building a condition check where I'm passing in the variable and a value to check. In this case the variable is an array value, but I can't get it to return it correctly //happens somewhere…
KPK
  • 442
  • 1
  • 5
  • 15
0
votes
1 answer

Defining PHP variable names using a loop and arrays - good practice?

I need to define a set of variables to a series $charta =''; $chartb =''; $chartc ='
Gideon
  • 1,878
  • 4
  • 40
  • 71
0
votes
1 answer

What was the reason to use "@$$var = .. " in this PHP code?

I have some code that returns error Undefined variable: dblink: This code is from a legacy system. "dblink" variable appears only inside this function in this one file. function db_connect($dbhost, $dbuser, $dbpass, $dbname = "") { if…
Dennis
  • 7,907
  • 11
  • 65
  • 115
0
votes
1 answer

Variable $_GET Variables

I am not sure if this is possible, but I'm trying to build a function that can build MYSQL queries. It has a base query. If URL has a get value (script.php?game=AGame) it will take that get variable and rename it. The script will then append the…
0
votes
1 answer

Unexpected results using dynamic variables

The following code using switch and dynamic variables should return "b1" but it returns "11". Is this a bug or am I doing something wrong?
Gary Carlyle Cook
  • 728
  • 11
  • 26
0
votes
3 answers

PHP: Create dynamic (variable) file name- Undefined variable: 65

I need to set a dynamic file name in PHP. So I wrote a small example script to represent the problems I am facing. When I run the following script, I get the following erroneous output, and the file created is just named .csv while it should be…
Solace
  • 8,612
  • 22
  • 95
  • 183
0
votes
1 answer

PHP - How to get a variable from another php file with a variable variable

I got a pretty tricky problem... I'm making a programm that will get the array from another php file, will sort it and will overwrite the php file with the new array. I'm making some test on 2 php files. One is index.php and the other one is…
Fearware
  • 325
  • 4
  • 13
0
votes
2 answers

Access Variable Variable in ForEach From Outside Class

I have a class that for the sake of example to make it easier to understand, takes an associative array, loops over it and assigns a variable name, based on key, and assigns it the value. This works fine in the class: class showItems { …
Alexander Wigmore
  • 3,157
  • 4
  • 38
  • 60
0
votes
1 answer

PHP Variable Variables Confusion

I'm using a while loop and mysql_fetch_array to display info on a page from a database. How can I give a variable name to certain radio button elements that are echoed on the page, and then use those variable names for the radio buttons as $_POST…
DanAdams
  • 165
  • 1
  • 3
  • 8
0
votes
1 answer

php and variable variables with array

Trying to end up with 7 arrays ($mon, $tue, $wed, $thu, $fri, $sat, $sun) that contain a value of either 0 or 1 for each hour of the day given initial array $hours. $hours is just a posted array that contains user selected hours for each day of the…
user756659
  • 3,372
  • 13
  • 55
  • 110
0
votes
3 answers

PHP variable variables in a foreach loop aren't working

This is a brilliant little trick if I can get it to work - I have hundreds data columns from dozens of tables spread across a dozen data forms (they are HTML print forms) and they are all html with embedded php variables. Very normal. However the…
user26676
  • 280
  • 3
  • 21