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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 16:01:29 2024 UTC