24
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP 7 から IIFE で、クロージャや無名クラスが即時実行できる

Last updated at Posted at 2015-07-22

PHP 7 から、JavaScript の IIFE(Immediately-invoked function expression)のような書き方で、クロージャや無名クラス(これも PHP 7 から)を即時実行できるようになります。

クロージャの場合

<?php

(function (string $message) {
    var_dump($message);
})('Hello!');

無名クラスの場合

<?php

(new class {
    public function say(string $message)
    {
        var_dump($message);
    }
})->say('Hello!');

実行したコード
http://3v4l.org/mK8W2

いやあ、便利。

24
23
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?