Created
March 16, 2023 13:59
-
-
Save calebporzio/d847abaed2ad491128352db21f3fac9d 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 memoize($target) { | |
static $memo = new WeakMap; | |
return new class ($target, $memo) { | |
function __construct( | |
protected $target, | |
protected &$memo, | |
) {} | |
function __call($method, $params) | |
{ | |
$this->memo[$this->target] ??= []; | |
$signature = $method . crc32(json_encode($params)); | |
return $this->memo[$this->target][$signature] | |
??= $this->target->$method(...$params); | |
} | |
}; | |
} |
You need a higher version of PHP that supports class properties in
constructors
…On Wed, Dec 27, 2023 at 1:00 AM Fahriza Rizky Lubis < ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
return new class ($target, $memo) {
function __construct(
protected $target,
protected &$memo,
) {}
why error?its says unexpected 'protected'
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/calebporzio/d847abaed2ad491128352db21f3fac9d#gistcomment-4808402>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA4AEMSOO4OLO6ALL6C3HYDYLO2P7BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTEMJUGMZTOMZSU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return new class ($target, $memo) {
function __construct(
protected $target,
protected &$memo,
) {}