PHP Strict Standards: Non-static method と出る場合の対処法

CakePHP1.2やCakePHP1.3を、PHP5.4以上に移行すると次のようなエラーが出る場合があります。

PHP Strict Standards:  Non-static method String::insert() should not be called statically, assuming $this from incompatible context in /…/cake/libs/debugger.php on line 683
PHP Strict Standards:  Non-static method Configure::read() should not be called statically, assuming $this from incompatible context in /…/cake/libs/debugger.php on line 308
PHP Strict Standards:  Non-static method Configure::getInstance() should not be called statically, assuming $this from incompatible context in /…/cake/libs/configure.php on line 163
PHP Strict Standards:  Non-static method CakeLog::write() should not be called statically, assuming $this from incompatible context in /…/cake/libs/debugger.php on line 311
PHP Strict Standards:  Non-static method CakeLog::getInstance() should not be called statically, assuming $this from incompatible context in /…/cake/libs/cake_log.php on line 230

PHP5.4 からエラー出力レベル E_ALL に E_STRICT が含まれるようになったことが原因です。
このため E_STRICT がエラーとして表示されます。

CakePHP では error_reporting() でエラー出力レベルを上書きしてしまいます。
このためphp.iniなどでの設定では対応できません。

最新のバージョンに更新するとエラーは解消されます。

1.3系の最新版のダウンロード先
https://github.com/cakephp/cakephp/archive/1.3.21.zip

https://github.com/cakephp/cakephp/releases/tag/1.3.21


最新のバージョンが手に入らない場合や、バージョンの変更が困難な場合はerror_reportingの該当箇所を変更します。

改修箇所は、『 E_ALL 』や『 ~E_DEPRECATED 』で全検索して変更を行います。

cake/bootstrap.php

error_reporting(E_ALL & ~E_DEPRECATED);
 ↓
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);

cake/console/cake.php

ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
 ↓
ini_set('error_reporting', E_ALL & ~E_DEPRECATED & ~E_STRICT);

cake/tests/cases/libs/cake_log.test.php

Configure::write('log', E_ALL & ~E_DEPRECATED);
 ↓
Configure::write('log', E_ALL & ~E_DEPRECATED & ~E_STRICT);

cake/tests/cases/libs/configure.test.php

$this->assertEqual($result, E_ALL & ~E_DEPRECATED);
 ↓
$this->assertEqual($result, E_ALL & ~E_DEPRECATED & ~E_STRICT);

$this->assertEqual(ini_get('error_reporting'), E_ALL & ~E_DEPRECATED);
 ↓
$this->assertEqual(ini_get('error_reporting'), E_ALL & ~E_DEPRECATED & ~E_STRICT);

CakePHP1系は、現在は更新がされていないので、いくつかの未改修の脆弱性が存在します。
CakePHP2系に更新するほうが安全です。

関連記事

スポンサーリンク

#演算子 ビットごとの排他的論理和

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る