I am playing with PHP5 and method chaining, following several StackOverflow examples. I would like to set up a generic show() method able to print only the desired property, please see the example:
<?php
class testarea{
public function set_a(){
$this->property_a = 'this is a'.PHP_EOL;
return $this;
}
public function set_b(){
$this->property_b = 'this is b'.PHP_EOL;
return $this;
}
public function show(){
echo var_dump($this->property_a); // ->... generalize this
return $this;
}
}
$ta=new testarea();
$ta->set_a()->set_b();
$ta->show();
?>
This echoes string(10) "this is a "
.
What I would like to do is a generic show() method which shows only the property that the set_a()
or the set_b()
methods have setted.
Is it possible?