Skip to content

Instantly share code, notes, and snippets.

@schmengler schmengler/Memoize.php
Last active Jul 20, 2017

Embed
What would you like to do?
<?php
trait Memoize
{
/**
* @var array [method][parameters]
*/
private $memoizedResults = [];
protected function memoizedCall($methodName, $args)
{
$serializedArgs = \serialize($args);
if (! isset($this->memoizedResults[$methodName][$serializedArgs])) {
$this->memoizedResults[$methodName][$serializedArgs] =
$this->subject->$methodName(...$args);
}
return $this->memoizedResults[$methodName][$serializedArgs];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.