Re: [CS] Naming Conventions (PHP5 OO)

From: Date: Wed, 16 Jun 2004 10:55:01 +0000
Subject: Re: [CS] Naming Conventions (PHP5 OO)
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-30746@lists.php.net to get a copy of this message
Klaus Guenther wrote: >Bertrand Mansion wrote: > >> Since when was it decided to prefix protected with an underscore ? >> >>I won't do that, even if it is a "CS". >> > >At some point you have to decide whether you want to be a PEAR developer >or not. Code not complying with CS will not be allowed in PEAR. Sorry >about that. And as you can see, it's now been put to vote. I will have to think about this... But for now, I won't use this rule even if it goes into CS. Anyway, there is a lot of code in PEAR that is not CS compliant, so it does not really matter I guess. A protected variable is different from a private variable. When PHP was considering everything public, an underscore was used to remind people that they shouldn't use such instance variables and this is a notation used in some other languages as well. But, you can freely access a protected variable in a subclass. With your underscore rule, how do I make a difference between a private and a protected variable in my subclass ? In this case, the underscore is misleading. This definition is too limited : > Similar to private members, protected > members restrict their usage scope to certain parts of code. In > contradiction to this, public members do not impose any scope > restrictons. There are similarities/differences between public and protected and between protected and private. To be fair, this definition should take them into consideration. We are in a case where GW Bush method can't work (I mean the black & white method). So if you want to be really, really smart, you would use: $A_ is for private $B_ is for protected $C_ is for public This way, users would know instantly what the scope is. But hey ! Isn't this already working ? Indeed. PHP people already provided the keywords "public", "private", "protected", so there is no need for $A_, $B_ and $C_ Even nicer, if you make a mistake by trying to access a variable out of scope, you will get an error. Cool ! And thanks to PHPDocumentor and the automatic API documentation, you can get these info instantly. So there is no need for an underscore. Or at least, this shouldn't be a CS rule. Bertrand Mansion Mamasam

« previous php.pear.dev (#30746) next »