Skip to content

Instantly share code, notes, and snippets.

@bu4ak
Last active December 31, 2020 08:39
Show Gist options
  • Save bu4ak/59d55f28c1ef12b655fa2ada0b1e8209 to your computer and use it in GitHub Desktop.
Save bu4ak/59d55f28c1ef12b655fa2ada0b1e8209 to your computer and use it in GitHub Desktop.
<?php
function foo(int $initialBaz)
{
return new class ($initialBaz) {
public function __construct(private int $baz) {}
public function getBaz(): int
{
return $this->baz;
}
public function setBaz(int $newValue): void
{
$this->baz = $newValue;
}
};
}
$fooObject = foo(3);
$currentValue = $fooObject->getBaz(); // 3
$fooObject->setBaz(5);
$newValue = $fooObject->getBaz(); // 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment