While working on a project, I've been making some changes and browsing around existing framework API docs for insight.
While perusing the Kohana docs, I noticed that the getters/setters of any given class are typically combined:
public function someProperty($value = null){
if(is_null($value){
return $this->_someProperty;
}
$this->_someProperty = $value;
return $this;
}
Rather than:
public function setSomeProperty($value){
$this->_someProperty = $value;
return $this;
}
public function getSomeProperty(){
return $this->_someProperty;
}
Is there any value in doing this (the former), beyond lessening the method count of a given class? I was always under the understanding that methods (functions in general) should be more descriptive of an action. Do other experienced developers cringe, even a tiny bit, when they see this?
I was just surprised to see a popular framework use such conventions (I haven't used Kohana of course)
Request::factory()
method is a bit of a beast, trying to handle initial and subsequent request creation calls simultaneously. Seems like a good place for method extraction. – Burkais_null($value)
, they should check iffunc_num_args() === 0
. – Elsewherenull
. If I ever find myself going the Kohana-esque route, I'll certainly use your suggestion as a check overis_null
or alternatives (I think they do a type check=== NULL
) – Burka