24
16

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で「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);

めでたし。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?