Is it possible to set a memory limit specifically to a variable ?
(This limit would be of course useless if greater than the memory_limit in php.ini.)
I would like $foo to be always less big than 1mb for example, but don’t care about other variables’s size.
No, it is not possible to impose a size limit on variables in PHP.
Depending on what you want to do, you could build a class with a setter function that checks the size before assigning a value to a variable of the class.