<?php
interface Counter
{
/** @return self */
public function count();
/** @return int */
public function getCount();
}
class ImmutableCounter implements Counter
{
private $count;
public function __construct($count = 0)
{
$this->count = (int) $count;
}
public function count()
{
return new ImmutableCounter($this->count + 1);
}
public function getCount()
{
return $this->count;
}
}
$counter = new FluentCounter();
$counter = $counter->count()->count()->count();
echo $counter->getCount();
Fatal error: Uncaught Error: Class "FluentCounter" not found in /in/i781B:31
Stack trace:
#0 {main}
thrown in /in/i781B on line 31
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Fatal error: Uncaught Error: Class "FluentCounter" not found in /in/i781B:31
Stack trace:
#0 {main}
thrown in /in/i781B on line 31
Process exited with code 255.
Fatal error: Uncaught Error: Class 'FluentCounter' not found in /in/i781B:31
Stack trace:
#0 {main}
thrown in /in/i781B on line 31
Process exited with code 255.