homepage Welcome to WebmasterWorld Guest from 54.237.213.31
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Variable Syntax in OO Scenario
mm1220

10+ Year Member



 
Msg#: 10964 posted 3:34 pm on Nov 30, 2005 (gmt 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!

 

Hanu

10+ Year Member



 
Msg#: 10964 posted 3:46 pm on Nov 30, 2005 (gmt 0)

Try PHP4's references:

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

or

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

madmac

10+ Year Member



 
Msg#: 10964 posted 5:35 pm on Nov 30, 2005 (gmt 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();

mm1220

10+ Year Member



 
Msg#: 10964 posted 7:34 pm on Nov 30, 2005 (gmt 0)

Thanks for that guys.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved