by yuri41 · 14y ago · 0 comments
So this code throws up a "Parse error: syntax error, unexpected 'function' (T_FUNCTION)"
class User
{
public static $mapping = array(
'username' => array(
'type' => 'string',
'length' => 32,
'unique' => true,
'nullable' => function() {
// Some logic to determine value.
}
)
);
} class User
{
public $mapping = array(
'username' => array(
'type' => 'string',
'length' => 32,
'unique' => true,
)
);
public function __construct()
{
$this->mapping['nullable'] = function() { echo "test"; };
$this->mapping['nullable']();
}
}
$user = new User();
And this doesn't: class User
{
public static $mapping = array(
'username' => array(
'type' => 'string',
'length' => 32,
'unique' => true,
)
);
public static function set()
{
self::$mapping['nullable'] = function() { echo "test"; };
self::$mapping['nullable']();
}
}
User::set();The reason is because Rasmus and a few others seem to think that using the syntax definition to do your type checking for you is a good idea, and that the hundreds of possible cases they didn't think of, don't matter.