Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cache closures in php

I want to cache an array which has also closures.

I've tried with:

  • serialize() - can't serialize closures
  • json_encode() - replaces closure with empty value
  • base64_encode() - doesn't accept arrays

What else to do for caching array containing also closures ?

like image 786
Valentin Tanasescu Avatar asked May 02 '26 22:05

Valentin Tanasescu


1 Answers

Closures in PHP can not be serialized "from the box" hence array with closures too. You can only use 3rd party ways/libraries to reach this. Discussed here: Serializing anonymous functions in php

like image 79
Viktor Avatar answered May 05 '26 14:05

Viktor