23
16

More than 5 years have passed since last update.

PHPで「Only variables should be passed by reference....」エラー

Last updated at Posted at 2016-03-03
PHP
return array_pop(explode(',', $text));

みたいなことをしようとしたらNoticeエラー吐いてた。

Notice: Strict (2048): Only variables should be passed by reference in ...

array_pop()に限らず、PHPでは参照渡しを要求するメソッドに値を直接渡して呼び出すと、上記のようなエラーを吐く。

ので、一旦渡す値を変数に格納する必要がある。

PHP
$exploded_text = explode(',', $text);
return array_pop($exploded_text);

めでたし。

23
16
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
23
16