php學習筆記:NULL

來源:互聯網
上載者:User
PHPmanual關於NULL的描述:
NULL

特殊的 NULL 值表示一個變數沒有值。NULL 類型唯一可能的值就是 NULL。

注:
NULL 類型是 PHP 4 引進的。

在下列情況下一個變數被認為是 NULL:

  • 被賦值為 NULL。

  • 尚未被賦值。

  • 被 unset()。

NULL 類型只有一個值,就是大小寫敏感的關鍵字 NULL。

好混亂啊,在javascript中還有關鍵字:var用來聲明變數,php沒有,貨幣符號($)後面跟個合法的字串,一個php的變數就誕生了,如上所說,它尚未被賦值,應該被認為是:NULL。使用strlen()試圖將其當作string,並算出它的長度,這樣做,php引擎不認為是錯用。
<?php
if(is_null($none))
    print "length=".strlen($none)."/n";//can output:length=0
else
    print "undefined variable/n";//can not come here
?>
<?
//PHPmanual說明:(1)is_null -- 
檢測變數是否為 NULL
//(2)NULL 類型只有一個值,就是大小寫敏感的關鍵字 NULL

$fo=null;

if(is_null($fo))
{//依據上述(2),並非大寫的NULL,本不該執行此處的,實際上並非如此,why?
    echo "/$fo=null is NULL/n";//output:$fo=null is NULL
}
$foo=NULL;
if (is_null($f)) {
    echo "/$f=NULL is also NULL";//out put:$f=NULL is also NULL
}
?>


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.