时间:2021-07-01 10:21:17 帮助过:8人阅读
class Base
{
    protected $_db = NULL;
   
    function __construct()
    {
    
    }
}
代码2:
class Base
{
    protected $_db;
   
    function __construct()
    {
    
    }
}以上代码有什么区别呢?
PHP 定义 Class 属性时,赋值NULL与不赋值有什么区别呢?
比如:
代码1:
class Base
{
    protected $_db = NULL;
   
    function __construct()
    {
    
    }
}
代码2:
class Base
{
    protected $_db;
   
    function __construct()
    {
    
    }
}以上代码有什么区别呢?
声明变量赋初值是个好习惯
没区别
http://php.com/manual/zh/language.types.null.php
class Base
{
    protected $_db = NULL;
   
    function __construct()
    {
    
    }
}
$b=new Base();
var_dump($b);