라이브러리

[PHP] CollectionAdd::__construct - CollectionAdd 생성자




CollectionAdd::__construct

PHP의 `CollectionAdd` 클래스는 `SplDoublyLinkedList` 클래스를 상속받아 사용할 수 있는 클래스입니다. `CollectionAdd` 클래스는 `SplDoublyLinkedList` 클래스의 `__construct` 메서드를 오버라이딩하여 사용할 수 있습니다.

`__construct` 메서드는 클래스의 생성자 메서드로서, 객체를 생성할 때 호출됩니다. 이 메서드는 `SplDoublyLinkedList` 클래스의 `__construct` 메서드를 호출하여 객체를 초기화합니다.

CollectionAdd::__construct 예제

#hostingforum.kr
php

class CollectionAdd extends SplDoublyLinkedList {

    public function __construct() {

        parent::__construct();

        $this->push('A');

        $this->push('B');

        $this->push('C');

    }

}



$collection = new CollectionAdd();



// CollectionAdd 객체의 요소 출력

while ($collection->valid()) {

    echo current($collection) . "
";

    $collection->next();

}



위 예제에서 `CollectionAdd` 클래스는 `SplDoublyLinkedList` 클래스를 상속받아 사용합니다. `__construct` 메서드는 `SplDoublyLinkedList` 클래스의 `__construct` 메서드를 호출하여 객체를 초기화합니다. 그리고 `push` 메서드를 사용하여 객체에 요소를 추가합니다.

CollectionAdd::__construct 사용 예

#hostingforum.kr
php

class CollectionAdd extends SplDoublyLinkedList {

    public function __construct() {

        parent::__construct();

        $this->push('A');

        $this->push('B');

        $this->push('C');

    }



    public function addElement($element) {

        $this->push($element);

    }

}



$collection = new CollectionAdd();



// CollectionAdd 객체의 요소 출력

while ($collection->valid()) {

    echo current($collection) . "
";

    $collection->next();

}



// 요소 추가

$collection->addElement('D');

$collection->addElement('E');



// CollectionAdd 객체의 요소 출력

while ($collection->valid()) {

    echo current($collection) . "
";

    $collection->next();

}



위 예제에서 `CollectionAdd` 클래스는 `SplDoublyLinkedList` 클래스를 상속받아 사용합니다. `__construct` 메서드는 `SplDoublyLinkedList` 클래스의 `__construct` 메서드를 호출하여 객체를 초기화합니다. 그리고 `push` 메서드를 사용하여 객체에 요소를 추가합니다.

`addElement` 메서드는 `push` 메서드를 사용하여 객체에 요소를 추가합니다.

CollectionAdd::__construct 사용하기

`CollectionAdd` 클래스는 `SplDoublyLinkedList` 클래스를 상속받아 사용할 수 있습니다. `__construct` 메서드는 `SplDoublyLinkedList` 클래스의 `__construct` 메서드를 호출하여 객체를 초기화합니다. 그리고 `push` 메서드를 사용하여 객체에 요소를 추가합니다.

`addElement` 메서드는 `push` 메서드를 사용하여 객체에 요소를 추가합니다.

CollectionAdd::__construct 사용하기

#hostingforum.kr
php

class CollectionAdd extends SplDoublyLinkedList {

    public function __construct() {

        parent::__construct();

        $this->push('A');

        $this->push('B');

        $this->push('C');

    }



    public function addElement($element) {

        $this->push($element);

    }

}



$collection = new CollectionAdd();



// CollectionAdd 객체의 요소 출력

while ($collection->valid()) {

    echo current($collection) . "
";

    $collection->next();

}



// 요소 추가

$collection->addElement('D');

$collection->addElement('E');



// CollectionAdd 객체의 요소 출력

while ($collection->valid()) {

    echo current($collection) . "
";

    $collection->next();

}



위 예제에서 `CollectionAdd` 클래스는 `SplDoublyLinkedList` 클래스를 상속받아 사용합니다. `__construct` 메서드는 `SplDoublyLinkedList` 클래스의 `__construct` 메서드를 호출하여 객체를 초기화합니다. 그리고 `push` 메서드를 사용하여 객체에 요소를 추가합니다.

`addElement` 메서드는 `push` 메서드를 사용하여 객체에 요소를 추가합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 584 페이지

검색

게시물 검색