Last active
December 31, 2020 08:39
-
-
Save bu4ak/59d55f28c1ef12b655fa2ada0b1e8209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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