4
2

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.

php5.6以降で配列を定数に定義できるようになっていたのでメモ

Posted at

結論

以下はphp7移行で使える書き方

define('DEVICE', [
	'pc' => 'windows',
	'phone' => 'iphone',
	'tablet' => 'ipad'
];

前提

php7、AWS sdk for phpのS3Clientクラスを使う際に設定する
オプション値を定数にして検証しています。
違う環境だと違う結果になるかもしれません。

エラーになった書き方

const DEVICE = [
	'pc' => 'windows',
	'phone' => 'iphone',
	'tablet' => 'ipad'
];
const OPTIONS = array('region' => 'ap-northeast-1', 'version' => 'latest', 'signature_version' => 'v4');

注意事項

define関数を使って定義するとグローバルに定義される。
constだと名前空間の定義が反映される。

色々と違いを検証してくれていたページを参考にさせていただきました。
ページ1
ページ2

4
2
0

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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?