0

I was looking at this implementation of a single linked list and noticed that inside the constructor the property $this->next is set to null.

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

Since php automatically sets the value of the property $next to null when it is declared outside of the constructor (ex public $next), isn't the line of code $this->next = NULL overkill?

class ListNode
{
    public $data;
    public $next;

    function __construct($data)
    {
        $this->data = $data;
        $this->next = NULL;
    }

    function readNode()
    {
        return $this->data;
    }
}

Also - I've seen this convention be used several times in php OOP. Is this a required convention in some other language?

4

1 回答 1

2

$this->next already is NULL, so there is no need to redeclare it.

于 2013-01-14T06:59:46.720 回答