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

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

WBOY
Release: 2016-06-06 20:52:40
Original
1254 people have browsed it

// 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;
    }));
  }
Copy after login
Copy after login

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;
    }));
  }
Copy after login
Copy after login

function($val) {

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

function ($val) {
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template