|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-02-25 23:16 UTC] jyoung at mycarepro dot com
Description:
------------
Varible Property Retrivel
Test script:
---------------
class y{
public $u = 123;
}
class a{
public $b = null;
public function __construct($test){
$this->b = $test;
}
public function $c(){
$p = new y();
$p->u; //Works
$p->$this->b; //Causes Error???
$tmp = $this->b;
$p->$tmp; //Works
}
}
$xyz = new a('u');
$xyz->c();
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 09:00:01 2025 UTC |
The -> operator is left associative, so $p->$this->b is interpreted as ($p->$this)->b. Instead you should write $p->{$this->b} to get the desired effect.