From: TAO R. <ron...@ho...> - 2001-05-14 01:20:27
|
>In light of the recent discussions about variable and method naming >conventions I'd like to add my suggestions based on what I've used in >numerous large projects in C++, Java, and lately in PHP that tend to >feel quite natural for at least a few pockets of programmers laboring in >unlabeled buildings in a few urban centers: > > >1.) Variable and method names: mixed case with lower case leading, with >leading or trailing underscores to signify private or global. > >e.g. $userName seems to be favored and $_userName for a local and >"private" variables, $userName_ for global and for "public". I would say for public just named like $myName rather than $myName_, because it seem much more easy and convenicnce for people who progam with BC API > >Sadly, function names are not case sensitive in php, so one has to be a >bit careful. > > > >2.) Getters and setters: > >I agree with Aderhold re: getProperty() and setProperty(...) seem quite >natural. > > > >It's too bad that php doesn't support function overloading, it would be >nice to be able to define setter and getter functions as: > >$obj->name_() - gets name value, name($stringVarHere) - sets name value >$obj->name_($someName_); sets the $_name property of $obj to equal >$someName_ > >It would be nice if binary cloud allowed this convention also. > > > >One simple workaround to the overloading problem: > >class test >{ >var $_name="not set"; > >function name_($val) for the function prototype, should be like setMe($foo1 = '', $foo2 = '') otherwise if user do not provide anything while calling the method, PHP engine give him any error response >{ > if(isset($val)) > $this->_name=$val; > else > return $this->_name; >} > >} >/* exercise class test */ >$obj=new test; >$tvar=$obj->name_(null); >echo "obj name is $tvar<br>"; >$obj->name_("set"); >$tvar=$obj->name_(null); >echo "obj name is $tvar<br>"; > > > >The above are just my own thoughts - I wanted to add my vote to the >discussion. Thank you. _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. |