
SplObjectStorage::removeAllExcept 메서드는 객체 저장소에서 특정 객체를 제외한 모든 객체를 삭제하는 메서드입니다.
이 메서드를 사용하기 전에 객체를 저장소에 추가하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$storage = new SplObjectStorage();
$obj1 = new stdClass();
$obj2 = new stdClass();
$storage->attach($obj1);
$storage->attach($obj2);
이 경우, SplObjectStorage::removeAllExcept를 사용하여 모든 객체를 삭제하려면 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$storage->removeAllExcept($obj1);
이 코드는 객체 $obj2를 삭제하고, 객체 $obj1만 남깁니다.
객체를 삭제하고 싶을 때는 detach 메서드를 사용합니다.
#hostingforum.kr
php
$storage->detach($obj1);
이 코드는 객체 $obj1를 삭제하고, 저장소에 남아있는 객체는 $obj2만 남깁니다.
SplObjectStorage::removeAllExcept를 사용하여 모든 객체를 삭제하는 방법은 clear 메서드를 사용하는 것입니다.
#hostingforum.kr
php
$storage->clear();
이 코드는 저장소에 저장된 모든 객체를 삭제합니다.
2025-05-01 16:45