PHP7.3 strpos()で非推奨表示が発生
- 2019.07.28
- PHP Prog
- deprecated, strpos
とあるプラグイン使っていたらstrpos()の箇所で非推奨(Deprecated)が発生。
Deprecated:  strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior実はPHP7.3からstrposの第2引数に文字列以外のものが入ってくると非推奨の表示がされるようです。地味にマニュアルに詳細が見つけられなかったので若干はまりました。
https://www.php.net/manual/ja/function.strpos.php
<?php
$haystack = 'abcdefg';
$needle   = 'cde';
// $haystackの中から'cde'が始まる位置を返す
echo strpos($haystack, $needle);
// 2あるプラグインの修正
該当箇所のソースコードを見ると$needleの部分にfalseが入ってくる可能性がありましたので、とりあえずこんな形で応急処置を行っておきました。
<?php
$haystack = 'abcdefg';
$needle   = 'cde';
// $haystackの中から'cde'が始まる位置を返す
if ( is_string($needle) ) {
    return strpos($haystack, $needle);
}
else {
    return false;
}- 
            前の記事  Raspberry pi 3 Model b でwebcamを使う 2019.06.27
- 
            次の記事  Googleカレンダーのスパム対策 2019.08.27
 
