ぶろぐ

日記です

それ動くのか…


いっその事エラーにして欲しかった。

<?php
// hoge.php
echo key;
takuan@www /tmp % php hoge.php
PHP Notice:  Use of undefined constant key - assumed 'key' in /tmp/hoge.php on line 2
key

↑ keyという文字列ということにして処理してる

<?php
// hoge2.php
$array = array();
$array["key1"] = "value1";

$value = $array[key1];
// ↓本当はこう書きたかった
// $value = $array["key1"];

// ↓keyが文字列として評価されてるっぽいので、値が取れてしまう
echo $value;
takuan@www /tmp % php hoge2.php
PHP Notice:  Use of undefined constant key1 - assumed 'key1' in /tmp/hoge2.php on line 6
value1%

なんで動くんだPHP\(^o^)/