Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.
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);

めでたし。

saekis
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away