Welcome to WebmasterWorld Guest from 54.146.217.179

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Variable Syntax in OO Scenario

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

Full Member

10+ Year Member

joined:Sept 13, 2003
posts:214
votes: 0


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)

Preferred Member

10+ Year Member

joined:Dec 8, 2003
posts:548
votes: 0


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)

Junior Member

10+ Year Member

joined:Sept 27, 2003
posts:156
votes: 0


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)

Full Member

10+ Year Member

joined:Sept 13, 2003
posts:214
votes: 0


Thanks for that guys.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members