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

Using array value with index as Variable Variable

The title may be a little confusing. This is my problem: I know you can hold a variable name in another variable and then read the content of the first variable. This is what I mean: $variable = "hello" $variableholder = 'variable' echo…
fedejp
  • 958
  • 3
  • 12
  • 20
0
votes
4 answers

Parse variables within string

I'm storing some strings within a *.properties file. An example of a string is: sendingFrom=Sending emails from {$oEmails->agentName}, to {$oEmails->customerCount} people. My function takes the value from sendingFrom and then outputs that string…
James
  • 5,137
  • 5
  • 40
  • 80
0
votes
3 answers

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…
Chris Dale
  • 2,222
  • 2
  • 26
  • 39
0
votes
2 answers

PHP Error when using variable variable to insert data into static variable

I'm not very good at this, so I'm sure this is a stupid question. I have a class: class debug { private static $messages = array(); private static $errors = array(); private static $all = array(); // includes both of above private static…
Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120
0
votes
4 answers

variable variables + objects in fields

I am trying to do something with variable variables and I got stuck on an object problem. Imagine this class setup: class A { public $field = 10; } class B { public $a; public function __construct() { $this->a = new A(); } } Now…
Santhos
  • 3,348
  • 5
  • 30
  • 48
-1
votes
1 answer

Variable global variable?

I'm trying to automatically sanitize input on an array of global variables like so: $sanitize = array('_POST', '_GET', '_REQUEST', '_COOKIE', '_SESSION'); foreach($sanitize as $type){ $property = trim(strtolower($type), '_'); …
wyqydsyq
  • 1,992
  • 1
  • 20
  • 28
-1
votes
3 answers

Variable variables, functions and classes

I just recently discovered variable variables in PHP, needless to say, it´s usefulness is immense: $name = "ABC"; $$name = "DEF"; echo ${"ABC"}; //Gives: DEF That got me thinking, which brings us to my question: Since we can have names that´s…
Marcus Hansson
  • 816
  • 2
  • 8
  • 17
-1
votes
1 answer

Extracting json data using variable variables?

I have a .json file with some data I'm trying to extract. What I need to know is how I would go about making the below variable dynamic. $MapData['MapData']['0,0']['type']; What I need to know is how I would replace the 0,0 with $x,$y variables.…
Born2DoubleUp
  • 109
  • 1
  • 10
-1
votes
1 answer

How to for loop 10 times values in single string using comma?

How I can use for loop PHP to create same result in $d4_c_d_v as below? Note: $d4_c_d_v must end without comma at the end. $d4_c_d_v = $g_demographics_value_0['id'] .','. $g_demographics_value_1['id'] .','. $g_demographics_value_2['id']…
-1
votes
1 answer

Class & Object Scope for Variable Variables in PHP

Question 1) Why is the Variable/variable $this->$template not visible to parse_and_return(), lines 42-50, but visible to $this->fetch, lines 456-472. I thought parse_and_return and $this->fetch belong to the same object, therefore $this->$template…
mmtalon
  • 47
  • 7
-1
votes
1 answer

Variable in global variable: "global variable{variable}". It works, but is it OK?

TL;DR: Say I have a global instantiated class $GLOBALS['my_plugin'] = instance(); and I want to use it somewhere else, but I dont know the name 'my_plugin'. Actually I do of course, but my helper files don't. In order to So I use; $plugin_name =…
Emin Özlem
  • 809
  • 7
  • 13
-1
votes
1 answer

PHP: Unable to use variable variables for multi-dimensional array access

I'm working on a config tool allowing flexible config for some code to fetch specific array elements (in this example, POST vars). (I am aware this problem could be solved with a recursive call, but ran into a curiosity I don't understand.) The…
Ben Dauphinee
  • 4,061
  • 8
  • 40
  • 59
-1
votes
1 answer

CodeIgniter access model with $$ fails

I have a model called Treatment in CodeIgniter. I want to load and use this model 'dynamically'. That is, I don't want to have to call it directly by name (I am trying to generalize some code to use whatever model I tell it). So, I do…
Jarrett
  • 1,767
  • 25
  • 47
-1
votes
1 answer

How can I use variable in $_POST[....]

That's my code: for($zm=1; $zm<=$ilosc; $zm++){ $aaa.$zm = $_POST['bbb.$zm']; } I want to use variable $zm in $_POST --> ( $_POST['bbb.$zm'] ); What is the proper form?
Yolo
  • 11
  • 1
1 2 3
11
12