Im preparing API methods for one of the system. Api will be available for few languages but first version will be released for the php. Im wondering what naming convention should use for accessor methods. I would like to have api interface very similar or even equal for each language. I was reading some libraries for php and noticed two naming convetion :
1) public accessor as set*() and get*() methods
class MyClass {
private $data;
public function getData() {
...
}
public function setData($value) {
...
}
}
2) drop out set/get prefix
class MyClass {
private $data;
public function data($value = null) {
if (!empty($value) && is_array($value)) {
$data = $value;
}
return $data;
}
}
Im not php programmer, I have experience in java and c/c++ so I would like to ask about suggestions which way to go for php ? Especially what is more readable, clear and understandable for php programmers.
I would like to read comments and sugestions.
all the best.
ps. if the topic is duplicated im sorry, would like to ask to point me to original topic.
Try this as a starting point. You will need to do more, but this should give you an idea, how to use __get and __set if this is an option.