In PHP (v 5.5.9-1ubuntu4.11) I'm not allowed to initialize data members with functions or arrays of functions. These two violate the PHP syntax on a basis of syntax error, unexpected 'function' (T_FUNCTION), expecting ')'
:
class Foo {
var $a = array(
function() {}
);
}
and:
class Foo {
var $a = function() {};
}
Nevertheless, this is allowed:
$a = array(function() {});
Why can't I assign functions to data members in classes?
For ease of reproduceability:
echo '<?php class Foo { var $a = array(function() {}); } ?>' | php
echo '<?php class Foo { var $a = function() {}; } ?>' | php
echo '<?php $a = array(function() {}); ?>' | php