HINA :: 工程幼稚園


偏執與強迫症的患者,算不上是無可救藥,只是我已經遇上我的良醫了。
 Author
 
Blog Image

my Gmail

Blog Look Score and Rank



Sitetag
 

Category

ALL (790)
Chats (199)
Life (36)
Photography (125)
Novel (60)
Fake stories (146)
Technical support (197)
WACOM (17)
Graphic arts (10)

Authors

Archive

Calendar

«   2010/03   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

  • Total : 526432
  • Today : 77
  • Yesterday : 202
Creative Commons License

本創作適用 姓名標示-非商業性-禁止改作 3.0 創用 CC 授權,台灣並依循所適用的授權條款。
views: 2280 times
超大字體(180%)放大字體(130%)原始字體(100%)
這好像是 PHP5 跟 PHP4 之間的一些問題。預設值來看,allow_call_time_pass_reference 是打開的,但是基於一些安全性的理由,有些伺服器會將這個設定關閉,而在 PHP 官方網站上,也說對於這個設定值在未來的版本將不繼續支援。至於為什麼會出現這樣的問題,主要是跟傳值與傳址有關。

在 PHP4 中,如果是 Call by Reference(or Call by Address),他是這樣運作:
function byReference( &$dest ) {
    $dest .= ' call by reference.';
}
$str = 'There is an example for';
byReference(&$str);
echo $str;
// 顯示結果為:There is an example for call by reference.


然而在 PHP5,因為他預設都是 pass by reference,假設你程式有寫的話,意思就是說,再傳入時不用特別指定他是 call by reference,就直接丟進去就好(也就是說他不會因為你加了 & 而強制使用傳址,一律使用傳值)。
function byReference( &$dest ) {
   $dest .= ' call by reference.';
}
$str = 'There is an example for';
byReference($str);
echo $str;
// 顯示結果為:There is an example for call by reference.


這是最主要的差異,當然我不是真的在 PHP4 上這樣測試過,但是官方是這樣說的。而 allow_call_time_pass_reference 的設定就是,你在呼叫函式的時候強制以傳址的方式傳遞,預設都是 On,而如果遇到將這個設定值關閉的主機,就必須要留意函式與呼叫的寫法。換句話說,就是你在呼叫的時候不能使用定址的方式去呼叫,不然會發生像是這樣的錯誤。大意是說,因為無法使用傳址的方式,所以你的呼叫將會使用傳值的方式去傳遞。
Warning: Call-time pass-by-reference has been deprecated; If youwould like to pass it by reference, modify the declaration of byReference(). If you would like to enable call-time pass-by-reference,you can set allow_call_time_pass_reference to true in your INI file in /web/www/index.php on line 11


所以,依照官方的說法,在 PHP5 呼叫時,直接使用 $ 給變數傳入即可,並不需要再另外指定 & 再傳入,這樣反而會發生錯誤(因為已經沒有了強制傳址的設定)。但,至於在 PHP4 中是否在呼叫時同時要指定 &,這個我就不得而知了。不過,目前看來,若是將 allow_call_time_pass_reference 關閉的話,勢必是要修改不少的 code 的。但是,由於這個功能在未來的 Zend/PHP 不再支援,所以在開發時,是必要將這個設定值關閉,以確保能夠在往後更新版本的環境下能正確執行。
創用 CC 授權
Creative Commons License
本創作適用 姓名標示-非商業性-禁止改作 3.0 創用 CC 授權,台灣並依循所適用的授權條款。
Bookmarks
 HEMiDEMi  Technorati  Del.icio.us  Digg  funP  Yahoo!  Furl
 相關文章 
作者資訊
author image
偏執與強迫症的患者,算不上是無可救藥,只是我已經遇上我的良醫了。

Trackback URL : http://blog.hinablue.me/trackback/589


Leave your greetings here.

[登入][OpenID是?]
Previous : 1 : ... 232 : 233 : 234 : 235 : 236 : 237 : 238 : 239 : 240 : ... 790 : Next