php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64300 Varible Property Retrivel
Submitted: 2013-02-25 23:16 UTC Modified: 2013-02-26 07:03 UTC
From: jyoung at mycarepro dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.4.12 OS: Windows 8
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jyoung at mycarepro dot com
New email:
PHP Version: OS:

 

 [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();


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-26 07:03 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-02-26 07:03 UTC] nikic@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 13 10:01:27 2025 UTC