#51099 [Opn->Csd]: Variable Variable with $this->
| From: | William dot McGuire at solacedev dot com | Date: | Sat, 20 Feb 2010 19:25:47 +0000 |
| Subject: | #51099 [Opn->Csd]: Variable Variable with $this-> | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-147898@lists.php.net to get a copy of this message | ||
ID: 51099
User updated by: William dot McGuire at solacedev dot com
Reported By: William dot McGuire at solacedev dot com
-Status: Open
+Status: Closed
Bug Type: Feature/Change Request
Operating System: Win XP
PHP Version: 5.3.1
New Comment:
I figured out the problem...it is not a bug...thank you.
Previous Comments:
------------------------------------------------------------------------
[2010-02-20 19:22:10] William dot McGuire at solacedev dot com
Just to let you know dynamically populating $this-> works fine...
ie...
$this->$db_key=$db_value where $db_key is username and $db_value is
"testuser" works fine...
it's just dynamically echoing $this->$field where $field = "username"
------------------------------------------------------------------------
[2010-02-20 19:18:58] William dot McGuire at solacedev dot com
Description:
------------
Consider 2 classes
class user
class reports extends user
user stores public variables such as public $username using
$this->username;
I want to be able to dynamically say in class reports
echo $this->$field where $field = "username", "first_name" etc.
Reproduce code:
---------------
---
From manual page: http://www.php.net/language.variables.variable
---
class user {
public $username;
function username() {
//queries from db table and gets
$this->username = $username; //from table
}
class reports extends user {
function userInfo($gid,$arrFieldstoReport) {
parent::__construct($gid)
//loop through $arrFieldstoReport
echo "username = " . $this->arrFieldstoReport[$i]
}
}
Expected result:
----------------
This should echo the following if $arrFieldstoReport[$i] = "username"
echo $this->arrFieldstoReport[$i];
//should echo
username = testusername (or any other username depending on what
group_id it is on)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=51099&edit=1