Welcome to WebmasterWorld Guest from 50.16.112.199

Forum Moderators: coopster & jatar k

Variable Syntax in OO Scenario

   
3:34 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



I've been using code like this for ages:
$a = 5; $b = 'a'; echo $$b;

which, of course, outputs: 5

How do I alter the syntax to work in an OO situation where the variables are:
$this->a and $this->b

Needless to say I've spent a good part of the morning messing
about with this and I'd like to be put out of my misery.

Thanks!

3:46 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



Try PHP4's references:

$a = 5; $b =& $a; echo $b;

or

$this->a = 5; $this->b =& $this->a; echo $this->$b;

5:35 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



well this is probably not going to show up right since the Webmaster World's code tag is a piece of sh*t, but hopefully you can make it out ok.


<?php

/**
* test
*/

Class Test {

var $a = 5;
var $b = 'a';

function run() {
echo $this->{$this->b};
}

}

$test = new Test();
$test->run();

7:34 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



Thanks for that guys.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month