0
0

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 1 year has passed since last update.

PHP:無名関数は奇妙だが便利だから使うところだが、使うならアロー関数を使ってしまいがち

Last updated at Posted at 2023-02-24

アロー関数もだが、無名関数も奇妙すぎる。それに、便利だから使うがアロー関数を使ってしまいがち。無名関数は関数名が無名なだけで量的にはほぼ減らせておらず、どうしても冗長になってしまい、数行に渡ってしまってコードが汚い。
それとも、奇妙なのはarray_mapなのか?

この点が奇妙。

  • 配列の要素の変数名を宣言してもいないうちに、使用時にいきなり使えてしまう(foreachは宣言をするのでわかるが、無宣言というのは奇妙すぎる)

function funcname(string ...$cards): array {
    return array_map(function ($card) {
        return substr($card, 1);
    }, $cards);
}
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?