douwen5833 2013-09-10 15:48
浏览 40
已采纳

create_function而不是lambda-function avartaco

I was trying to implement avartaco, which is like gravatar.

In order to make it work in php version < 5.3

If you want to make it work on PHP less than 5.3.0, find string

array_walk($shape, function(&$coord, $index, $mult) { $coord *= $mult; }, self::SPRITE_SIZE);

and rewrite it for using create_function() instead of lambda-function.

I was getting error Parse error: syntax error, unexpected T_FUNCTION in that same line array_walk.My php version is 5.2.17 <5.3 But I have no idea what is meant by rewriting by createfunction?

So what should I change in that line to make it work in php version < 5.3

private function GetShape($type) {

    switch($type) {

        case 'side':

            $shape_id = hexdec(substr($this->_hash, 22, 1)) & (sizeof($this->_shapesSide) - 1);

            $shapes = $this->_shapesSide;
        break;
        case 'center':
            $shape_id = hexdec(substr($this->_hash, 23, 1)) & (sizeof($this->_shapesCenter) - 1);

            $shapes = $this->_shapesCenter;
        break;

        case 'corner':
            $shape_id = hexdec(substr($this->_hash, 24, 1)) & (sizeof($this->_shapesCorner) - 1);

            $shapes = $this->_shapesCorner;
        default:
        break;

    }

    $shape = $shapes[$shape_id];

    array_walk($shape, function(&$coord, $index, $mult) { $coord *= $mult; }, self::SPRITE_SIZE);
    return $shape;

}
  • 写回答

3条回答 默认 最新

  • duanju8431 2013-10-09 05:51
    关注

    Simply do the following

    array_walk(
        $shape,
        create_function(
            '&$coord, $index, $mult',
            '$coord *= $mult;'
        ),
        self::SPRITE_SIZE
    );
    

    I have tested avatarico in php < 5.3 and it works!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大