rfc:property-capture
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
rfc:property-capture [2023/04/22 21:16] – imsop | rfc:property-capture [2023/04/23 18:54] – imsop | ||
---|---|---|---|
Line 155: | Line 155: | ||
===== Examples ===== | ===== Examples ===== | ||
- | **TODO** | + | **TODO |
+ | |||
+ | Create a struct-like object with readonly public properties: | ||
+ | |||
+ | <code php> | ||
+ | $id = get_next_id(); | ||
+ | $name = get_name(); | ||
+ | $user = new readonly class use ($id, $name) {}; | ||
+ | echo " | ||
+ | $user-> | ||
+ | </ | ||
+ | |||
+ | Decorate a [[https:// | ||
+ | |||
+ | <code php> | ||
+ | use Psr\Log\{LoggerInterface, | ||
+ | |||
+ | function decorate_logger(LoggerInterface $logger, string $contextKey, | ||
+ | | ||
+ | use ($logger as private $innerLogger, | ||
+ | implements LoggerInterface | ||
+ | { | ||
+ | public function log($level, string|\Stringable $message, array $context = []): void { | ||
+ | $context[$this-> | ||
+ | $this-> | ||
+ | } | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
===== Reflection ===== | ===== Reflection ===== |
rfc/property-capture.txt · Last modified: 2023/04/23 21:15 by imsop