Home  >  Article  >  Backend Development  >  php underscore的代码报错, 帮忙瞧瞧

php underscore的代码报错, 帮忙瞧瞧

WBOY
WBOYOriginal
2016-06-06 20:52:401196browse

// Return a copy of the array with falsy values removed
  public function compact($collection=null) {
    list($collection) = self::_wrapArgs(func_get_args(), 1);
    
    $collection = self::_collection($collection);
    
    $__ = new self;
    return self::_wrap($__->select($collection, function($val) {
      return (bool) $val;
    }));
  }

function($val) {

代码来自php underscore, 这个地方报错, 似乎不能做参数.

回复内容:

// Return a copy of the array with falsy values removed
  public function compact($collection=null) {
    list($collection) = self::_wrapArgs(func_get_args(), 1);
    
    $collection = self::_collection($collection);
    
    $__ = new self;
    return self::_wrap($__->select($collection, function($val) {
      return (bool) $val;
    }));
  }

function($val) {

代码来自php underscore, 这个地方报错, 似乎不能做参数.

function ($val) {

这种写法是lambda函数(匿名函数)的写法,以前经常出现在js等脚本语言中。但是从php 5.3开始支持这种匿名函数。所以你遇到的问题就是php版本不够造成的,升级到最新版本的php 5.3.x就可以解决这个问题。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn