Welcome Guest, Not a member yet? Register   Sign In
Setter / Getter Best Practice 2016
#1

I have been doing this (see below) for sometime and wanted to know if this would be considered best practice for a PHP setter/getter function?

PHP Code:
public function plugin_prefix($prefix=null) {
 
 /* return value if no value sent in */
 
 if ($prefix === null) {
 
  return $this->plugin_prefix;
 
 }

 
 /* set file extension */
 
 $this->plugin_prefix $prefix;

 
 /* chain-able */
 
 return $this;



This allows me to set multiple settings using


PHP Code:
$this->my_object->plugin_prefix('foo')->extension('bar')->something_else('foobar'); 

and get a value with


PHP Code:
$plugin $this->my_object->plugin_prefix(); 


I look forward to your comments...

DMyers
Reply


Messages In This Thread
Setter / Getter Best Practice 2016 - by dmyers - 07-25-2016, 04:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB