[php-src] Issue #10139: [Feature request] Add class cache syntax

From: Date: Tue, 20 Dec 2022 16:26:37 +0000
Subject: [php-src] Issue #10139: [Feature request] Add class cache syntax
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243204@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10139 Author: Nuranto ### Description It happens a lot to use class property as a caching method. For example : ``` class OrderStatus { protected $statusLabels = []; public function getStatusLabel(int $statusCode) { if(!isset($this->statusLabels[$statusCode])) { $this->statusLabels[$statusCode] = $this->loadStatusLabelFromDatabase($statusCode); } return $this->statusLabels[$statusCode]; } } ``` Would be great to have some new syntax to do this behind the scene : ``` class OrderStatus { public cacheable function getStatusLabel(int $statusCode) { return $this->loadStatusLabelFromDatabase($statusCode); } } ``` Of course, some rules should exists, like a function cannot be cached if some parameters are not typed or not a basic type. What do you think ?

« previous php.bugs (#243204) next »