A
A
Andrzej Wielski2013-12-15 13:15:26
PHP
Andrzej Wielski, 2013-12-15 13:15:26

Storing a function inside a php session?

Next code:

$_SESSION['test'] = function(){
  echo 'test';
};

Spitting error
Fatal error: Exception thrown without a stack frame in Unknown on line 0

And I desperately need to store functions inside the session, or somehow transfer them to another script.
What is the best way to implement this?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrzej Wielski, 2013-12-15
@wielski

Solved thanks to @LastDragon

Out of the box - nothing, but you can see (did not use it myself) PHP Super Closure ("a library that allows you to serialize closures in PHP", found in one of the digests ).

M
Max, 2013-12-15
@7workers

If it's desperate, maybe eval () of the string will do?

D
Damir Makhmutov, 2013-12-15
@doodoo

Weird:

php > $func = function() { echo 'test'; };
php > $func();
test
php > session_start();
php > var_dump($_SESSION);
array(0) {
}
php > $_SESSION['test'] = $func;
php > $_SESSION['test']();
test

Do you have a standard session storage mechanism?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question