Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中除变量外的类名称_Php_Function_Laravel_Class - Fatal编程技术网

PHP中除变量外的类名称

PHP中除变量外的类名称,php,function,laravel,class,Php,Function,Laravel,Class,在PHP中我不理解这一点,函数括号中除了类名和变量之外还有一个类名和变量,有时可以用逗号分隔多个类,然后所有的类公共方法都可以通过使用与类关联的变量来使用 Schema::create('news_feeds', /*Here*/ function (Blueprint $table)/*To Here*/ { $table->increments('id'); $table->string('title');

在PHP中我不理解这一点,函数括号中除了类名和变量之外还有一个类名和变量,有时可以用逗号分隔多个类,然后所有的类公共方法都可以通过使用与类关联的变量来使用

        Schema::create('news_feeds', /*Here*/ function (Blueprint $table)/*To Here*/ {
            $table->increments('id');
            $table->string('title');
            $table->text('content');
            $table->string('date');
            $table->timestamps();
        });
这段代码来自laravel脚本

我试图搜索它是如何工作的,但我不知道它叫什么,那么在PHP中这种做事情的方法叫什么呢

  Schema::create('news_feeds', function(Blueprint $table) {
//^       ^      ^             ^        ^         ^
//|       |      |             |        |         |
//|       |      |             |        |         -- 1st function param.
//|       |      |             |        -- Typehint for 1st function param.
//|       |      |             -- Second method argument
//|       |      -- First method argument
//|       --Method Name
//--Class Name
  });
您需要了解,因为您使用的是类似于Laravel的框架,所以有些行为不属于PHP本身

您不理解的代码段称为
匿名函数
,它通常用作
回调

在后台,拉威尔正在做这件事:

  • 好的,他调用了
    Schema::create
    来创建一个名为
    news\u feed
  • 让我们创建一个
    蓝图
    对象
  • 我会将此对象发送给用户修改。(Laravel在此调用您的回调,并将Blueprint作为参数)
  • 一旦执行了
    回调
    ,蓝图将被“执行”,这里的表实际上是在数据库上创建的
如果您确实想知道这是如何实现的,请转到类
illighted\Database\Schema\Builder
并查找方法
create

为了让您的生活更轻松,使用像PHPStorm这样的IDE,您可以通过使用
ctrl+b
shortcut以简单的方式遵循方法、类和变量

public function create($table, Closure $callback)
{
    $blueprint = $this->createBlueprint($table);

    $blueprint->create();

    $callback($blueprint);

    $this->build($blueprint);
}
看看我告诉你的创建方法步骤

您需要了解,因为您使用的是类似于Laravel的框架,所以有些行为不属于PHP本身

您不理解的代码段称为
匿名函数
,它通常用作
回调

在后台,拉威尔正在做这件事:

  • 好的,他调用了
    Schema::create
    来创建一个名为
    news\u feed
  • 让我们创建一个
    蓝图
    对象
  • 我会将此对象发送给用户修改。(Laravel在此调用您的回调,并将Blueprint作为参数)
  • 一旦执行了
    回调
    ,蓝图将被“执行”,这里的表实际上是在数据库上创建的
如果您确实想知道这是如何实现的,请转到类
illighted\Database\Schema\Builder
并查找方法
create

为了让您的生活更轻松,使用像PHPStorm这样的IDE,您可以通过使用
ctrl+b
shortcut以简单的方式遵循方法、类和变量

public function create($table, Closure $callback)
{
    $blueprint = $this->createBlueprint($table);

    $blueprint->create();

    $callback($blueprint);

    $this->build($blueprint);
}

请看我告诉您的创建方法步骤。

这些是函数参数,类是变量名表示实例的类型。变量$somevar必须是SomeClass类型。如果php7的thrownException不是异常,则早期版本@Jrenkt中的致命错误此类型的函数称为匿名函数:这些是函数参数,类是变量名表示实例的类型。变量$somevar必须是SomeClass类型。如果不是php7的thrownException异常,则在早期版本@Jrenkt中出现致命错误这种类型的函数称为匿名函数:这正是我需要看到的继续谢谢你这正是我需要看到的继续谢谢你非常感谢