php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #26554 __get($variable) do not work.
Submitted: 2003-12-08 13:20 UTC Modified: 2004-09-29 09:42 UTC
From: jonas at gauffin dot org Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.0b2 (beta2) OS: winxp
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: jonas at gauffin dot org
New email:
PHP Version: OS:

 

 [2003-12-08 13:20 UTC] jonas at gauffin dot org
Description:
------------
__get do not work as I expected. I think that it should override member variables (and return them).



Reproduce code:
---------------
class testClass
{
	private $myTest;
	
	function __get($memberVariable)
	{
		if ($memberVariable == 'myTest')	 
			return $this->myTest;
	}	
}


$test = new testClass;
echo $test->myTest;


Expected result:
----------------
imho that's valid code. I do not want to change the variables to public since they are readonly. One way to do it would be to add a prefix to the member variables, but since $this have to be used to access the variables that would produce ugly code.

Actual result:
--------------
PHP Fatal error: Cannot access private property testclass::$myTest in E:\projects\inetpub\progga.se\test.php on line 46 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-08 13:22 UTC] derick@php.net
This is not really a bug, making it a feature request.
 [2004-09-29 09:32 UTC] php at nowhere dot net
This test code appears to work now. Should this be closed?
 [2004-09-29 09:42 UTC] tony2001@php.net
Sample code work ok now -> closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 23:01:35 2024 UTC