Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closures with PHP

Tags:

closures

php

I have a weird problem trying to use closures in PHP. When assigning a closure to a variable, I get a null value. But when displaying the closure with var_dump(), everything is alright.

Here is a source code that summarizes the problem:

$f = function() {};
var_dump($f); // 'null'

var_dump(function() {}); // 'object(Closure)[1]'

I'm using PHP 5.3.1.

Edit: I forgot to mention, I have this problem only when I'm using PHP via Apache. I don't have issues when using PHP CLI.

like image 927
scastiel Avatar asked Nov 01 '22 10:11

scastiel


1 Answers

A colleague found the answer to the problem: the responsible is eAccelerator! Apparently it's not compatible with PHP 5.3 closures... (source)

Disabling it solved the problem.

Thanks for your help!

like image 62
scastiel Avatar answered Nov 09 '22 07:11

scastiel