Skip to content

Instantly share code, notes, and snippets.

@jiromm
Created July 27, 2018 09:45
Show Gist options
  • Save jiromm/e40ef73076f2af82dc754be22e1cd0e7 to your computer and use it in GitHub Desktop.
Save jiromm/e40ef73076f2af82dc754be22e1cd0e7 to your computer and use it in GitHub Desktop.
<?php
class x {
public $sum = 0;
public function __invoke($num = 0)
{
$this->sum += $num;
return $this;
}
public function __toString()
{
try {
return (string)$this->sum;
} finally {
$this->sum = 0;
}
}
}
$x = new x();
echo $x(7)(5)(3) . PHP_EOL;
echo $x(1)(2)(3)(4) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment