[請益] array或$_GET[], []內不用引號的設定問題

看板PHP作者 (cpqq)時間16年前 (2009/05/01 14:11), 編輯推噓3(308)
留言11則, 5人參與, 最新討論串1/3 (看更多)
各位前輩, 我有好幾個 PHP 範例程式,我直接執行都會有錯誤,因為這幾個範例程式 在$_POST[month] 的中括弧[]內沒有引號,所以會顯示錯誤: Notice: Use of undefined constant month - assumed 'month' in ... 請問要做什麼設定才能正確執行這類型的原始碼呢? note: 看起來不是範例有錯,因為書上附的範例有好幾十個沒加quote... 先謝謝了 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.131.171.100

05/01 14:33, , 1F
請加quote
05/01 14:33, 1F

05/01 14:42, , 2F
請把quote加上去..另外這本書是哪本..他錯了...
05/01 14:42, 2F

05/01 16:21, , 3F
XD 把 notice 關掉 *誤*
05/01 16:21, 3F

05/01 17:40, , 4F
php.net/manual/en/language.constants.syntax.php
05/01 17:40, 4F

05/01 17:41, , 5F
第四段 If you use an undefined constant
05/01 17:41, 5F

05/01 17:41, , 6F
PHP assumes that you mean the name of the
05/01 17:41, 6F

05/01 17:42, , 7F
constant itself, just as if you called
05/01 17:42, 7F

05/01 17:42, , 8F
it as a string (CONSTANT vs "CONSTANT").
05/01 17:42, 8F

05/01 17:45, , 9F
所以要看上下的程式才能決定是不是可以用加引號解決
05/01 17:45, 9F

05/02 02:27, , 10F
也不一定...也許你的 php 套件也定了不少常數
05/02 02:27, 10F

05/02 02:28, , 11F
總之加引號最穩
05/02 02:28, 11F
文章代碼(AID): #19-fA0Tl (PHP)
文章代碼(AID): #19-fA0Tl (PHP)