Hi how can I make a class object with the possibility of doing this:
<?php
$someClass = new SomeClass;
$sum = $someClass->addValues(1,22)->sumValues();
echo $sum; // to give me 23
?>
Sorry for asking! This is what I meant and I just got the idea, so - Sorry for the Post.
<?php
class SomeClass {
private $values = array();
public function addValue(){
$this->values = func_get_args();
return $this;
}
public function getSum(){
$sum = array_sum($this->values);
return $sum;
}
}
$SomeClass = new SomeClass;
$result = $SomeClass->addValue(1,22,44,51)->getSum();
echo $result;
?>
And for all of those who answered - Sorry but this was only an EXAMPLE, so I asked How to do it to help me not to argue with me is it an overkill or not. I needed the way to do it. Not like I will use the same code.