7
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 5 years have passed since last update.

am関数は、CakePHP3では削除されています。

参考:CakePHP各バージョンのグローバル関数
CakePHP 1.3
https://book.cakephp.org/1.3/ja/The-Manual/Developing-with-CakePHP/Global-Constants-and-Functions.html#am
CakePHP 2.0
https://book.cakephp.org/2.0/ja/core-libraries/global-constants-and-functions.html
CakePHP 3.0
https://book.cakephp.org/3.0/ja/core-libraries/global-constants-and-functions.html

ですので、CakePHPを最新バージョンにするのであれば、am関数は使えなくなります。

置き換えるなら、array_merge関数になるでしょう。
http://php.net/manual/ja/function.array-merge.php

しかし、am関数をarray_merge関数に置き換えるときは、引数に配列以外(特にnull)が入るパターンがないか確認が必要です。

am関数の内容は以下の通り。

function am() {
  $r = array();
  $args = func_get_args();
  foreach ($args as $a) {
    if (!is_array($a)) {
      $a = array($a);
    }
    $r = array_merge($r, $a);
  }
  return $r;
}

引数が配列でなければ配列に変換する処理があります。
この処理に頼った実装をしていると、array_merge関数に変換したときにエラーとなる可能性があります。

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