php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35548 $class->${'varname'} does not work
Submitted: 2005-12-04 21:58 UTC Modified: 2005-12-05 01:43 UTC
From: capiCrimm at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.1 OS: GNU Debian Sarge
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: capiCrimm at gmail dot com
New email:
PHP Version: OS:

 

 [2005-12-04 21:58 UTC] capiCrimm at gmail dot com
Description:
------------
Where you can do ${'var'} with a normal variable trying to 
do the same thing with a class prop. results in a fatal 
error. It happens inside{$this} and outside the class. 
With public, private, and protected. It does work 
correctly with static variables. 

Reproduce code:
---------------
<?php

class Test
{
  protected $variable = 'one';

  public function test(){
    print $this->variable;
    print $this->${'variable'};
  }

}
$t = new Test;

?>

Expected result:
----------------
oneone 

Actual result:
--------------
one 
 Fatal error: Cannot access empty property 
in /www/unstable/apache2/php5/admin/mRio/mRioDUM/bella1/test.php 
on line 9 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-04 22:06 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

>Where you can do ${'var'} with a normal variable 
That doesn't work either.
 [2005-12-04 23:35 UTC] capiCrimm at gmail dot com
I'll agree that this may not be a bug, rather how you  
choose to develop the engine. However ${} does work with  
normal variables and class static variables. The following 
prints ``five'' as  
expected.  
<?php  
  
$one = 'five';  
print ${'one'};  
  
?>
 [2005-12-05 01:43 UTC] capiCrimm at gmail dot com
eh. I figured it out, instead of $this->${'var'} you use 
$this->{'var'}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC