php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #11756 Private, Protected variables in classes
Submitted: 2001-06-27 17:47 UTC Modified: 2002-04-27 15:35 UTC
From: alavoor at yahoo dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS: Linux
Private report: No CVE-ID: None
 [2001-06-27 17:47 UTC] alavoor at yahoo dot com
I have a good idea. It is extremely easy to implement private, protected variables in classes.

PHP can use the name mangling of variables to implement private variables in classes. This technique is used by python language.

What you do is - PHP will read the class and simply change the variable names to <variablename>_timestamp. Where timestamp is unique id got by time() function.

Classes need private, protected variables. What do you say??


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-27 18:05 UTC] alavoor at yahoo dot com
for example:
class 
{
	private:
		var $myvar;
		var $myvar2:
	public:
		var $myvar3;

	function myfoo()
	{
		print "the variable is : " . $myvar
	}
}

will be converted "on the fly" by PHP interpreter to 
class
{
	var $myvar_993679346;
	var $myvar2_993679346:
	var $myvar3;

	function myfoo()
	{
		print "the variable is : " . $myvar_993679346;
	}
}

Note that 993679346 is the time stamp got by time(). PHP interpreter when it starts up will store this
timestamp value in a global var and use it throught to mangle all the private variables declared in
all the classes in all the files..

 [2001-06-28 06:30 UTC] derick@php.net
This will be dealt with with the new version of the Zend engine. The timeframe is a few months... so please stay tuned...
 [2002-04-27 15:35 UTC] jimw@php.net
implemented in ZE2.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC