<?php
class Classe {
public function calcula(){
$resultado = ($this->valor * 2);
$this->valor = $resultado;
return $resultado;
}
public function valor(int $valor = 10){
$this->valor = $valor;
return $this;
}
}
$classe = new Classe;
echo $classe->valor(2)->calcula();
echo '<br>';
echo $classe->calcula();
echo '<br>';
echo $classe->calcula();
echo '<br>';
echo $classe->calcula();
PD9waHAKCmNsYXNzIENsYXNzZSB7CiAgIHB1YmxpYyBmdW5jdGlvbiBjYWxjdWxhKCl7CiAgICAgICRyZXN1bHRhZG8gPSAoJHRoaXMtPnZhbG9yICogMik7CiAgICAgICR0aGlzLT52YWxvciA9ICRyZXN1bHRhZG87CiAgICAgIHJldHVybiAkcmVzdWx0YWRvOwogICB9CgogICBwdWJsaWMgZnVuY3Rpb24gdmFsb3IoaW50ICR2YWxvciA9IDEwKXsKICAgICAgJHRoaXMtPnZhbG9yID0gJHZhbG9yOwogICAgICByZXR1cm4gJHRoaXM7CiAgIH0KIAp9CgokY2xhc3NlID0gbmV3IENsYXNzZTsKCmVjaG8gJGNsYXNzZS0+dmFsb3IoMiktPmNhbGN1bGEoKTsKZWNobyAnPGJyPic7CmVjaG8gJGNsYXNzZS0+Y2FsY3VsYSgpOwplY2hvICc8YnI+JzsKZWNobyAkY2xhc3NlLT5jYWxjdWxhKCk7CmVjaG8gJzxicj4nOwplY2hvICRjbGFzc2UtPmNhbGN1bGEoKTs=