Re: do_declare_property()

From: Date: Wed, 12 Jul 2000 17:38:36 +0000
Subject: Re: do_declare_property()
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-24349@lists.php.net to get a copy of this message
On Wed, 12 Jul 2000, Teodor Cimpoesu wrote: > Hi John! > On Wed, 12 Jul 2000, John Keiser wrote: > > > > Of course it will know it's a class, and when parsing the class def. > > > the rewrite takes place. > > > > > > Of course, we don't really need to have `$this->__bar', I though we > > > can also have private var $bar', and rewrite the member to > > > _Class__bar' > > > to ensure it's `privateness'. > > > > > > > Simple question. Couldn't you have a normal public variable that happened > > to start with two underscores? Isn't there a $ or something that cannot be > > used in an ordinary variable that could be used for this internal marker? > > > > What would happen in the following example: > > > > class test { > > var __yoyoman; > > private var yoyoman; > > } > > > > Or even simpler, what if just var __yoyoman was declared? Would the access > > fail even though it was public? > Depends on the implementation of the private. > I proposed it the Python way: rewrite the variable name to something else, > and when you encounter an access request, go get the actual attribute: > i.e. > class Foo { > var $__myprivate; > function getIt() { return $this->__myprivate;} > } > what should happen? when the class is parsed, don't add `__myprivate' as > an attribute, but add instead _Foo__myprivate. > Then apply a simple rule when the user wants `__myprivate': > is the access within a class method? yes - get _Foo__myprivate, else we have > an access violation. > e.g. > $this->__myprivate is actually translated into something like > $this->_Foo__myprivate. > > you need the class name to reconstruct the real attribute, and you will always > have it when within a method (I guess :) > > Same goes with `private' keyword, but there is some glitch here. > Andi pointed you would need to know the class at compile time, so to check > if $this->yoyoman' is private or not, but with this > __' hack you just look > at the variable name: does it start with 2 x _ ? deny access if not in a method scope. > This is what I wrote this afternoon, if (varname begins with '__') verify_we're_calling_From_the_object() else error(acces violation) __variable would indeed raise a problem... because a normal variable can start with '__' too.. (Perhaps this is what you meant Andi) you can't see wether you mean that variable is a private one or not... Look, rewriting the url name one way is no problem.. private var $private_var; // become _my_object__private_var; But retrieving it is.. (simplified example below) if (Zend_hash_find (ht, "private_var) == FAILURE) { // Pass 1.. if (Zend_hash_find(ht,"__private_var")) // Pass 2! SLOW DOWN. } I could think up a fix for this (storing the variables with unusable characters e.g. **private_var or whatever..) but I'm not sure wether I should do this.. if (variable_name prefixed with '__') { strip '__' and replace with *; Zend_Hash_Find(ht, variable_name) } -- Mathieu > -- teodor > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.dev (#24349) next »