php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15871 variable variables need { } to work with classes
Submitted: 2002-03-05 07:13 UTC Modified: 2002-03-05 08:34 UTC
From: greg at mtechsolutions dot ca Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.1.2 OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: greg at mtechsolutions dot ca
New email:
PHP Version: OS:

 

 [2002-03-05 07:13 UTC] greg at mtechsolutions dot ca
When using a variable variable in a class, $$this->varname does not work, ${$this->varname} must be used. 

Here is a simple script to show this in action. Put the {} in and it will work:

<?
$id = "yes";

class testClass {
	var $varname;
	
	function testClass($varname) {
		$this->varname = $varname;
	}
	
	function foo() {
		global $$this->varname;
		
		echo "$".$this->varname." is ".$$this->varname;
	}
}

$test = new testClass("id");
$test->foo();

?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-05 07:22 UTC] derick@php.net
Actually this isn't a bug, but just 'how things work'.

regards,
Derick
 [2002-03-05 08:34 UTC] rasmus@php.net
Just to give you a better answer here.  Consider $$a->b
Does this mean the the class name $$a with the property b or  the variable property $a->b?  See the vagueness here?  It could be interpreted as either ${$a->b} or {$$a}->b.  That's why the {}'s are needed to resolve this ambiguity.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 05 21:01:27 2024 UTC