对于在构造函数外部声明的属性,在构造函数内部将其值初始化为null是否过分?


For a property declared outside of constructor, is it overkill to initialize its value to null inside the constructor?

我正在查看这个单链表的实现,并注意到在构造函数内部,属性$this->next被设置为null

http://code.activestate.com/recipes/576498-implementation-of-a-single-linked-list-in-php/

由于php自动设置属性$next的值为null时,它是在构造函数外声明(如public $next),是不是行代码$this->next = NULL过度杀死?

class ListNode
{
    public $data;
    public $next;
    function __construct($data)
    {
        $this->data = $data;
        $this->next = NULL;
    }
    function readNode()
    {
        return $this->data;
    }
}

也-我看到这个约定在php OOP中被使用了好几次。这在其他语言中是必需的约定吗?

$this->next已经是NULL了,所以没有必要重新声明。