개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.08.02 03:03

SplObjectStorage::removeAll 메서드 사용에 대한 질문

목록
  • 버전컨트롤러 1일 전 2025.08.02 03:03
  • 8
    1
SplObjectStorage::removeAll 메서드를 사용하여 모든 객체를 제거할 수 있나요?
그리고 removeAll 메서드를 사용한 후에도 객체가 남아있는지 확인할 수 있는 방법은 무엇인가요?

    댓글목록

    profile_image
    나우호스팅  1일 전



    SplObjectStorage::removeAll 메서드는 모든 객체를 제거할 수 있습니다.

    #hostingforum.kr
    php
    
    $storage = new SplObjectStorage();
    
    $storage->attach(new stdClass());
    
    $storage->attach(new stdClass());
    
    
    
    $storage->removeAll();
    
    
    
    var_dump($storage->count()); // 0
    
    


    객체가 남아있는지 확인하기 위해서는 $storage->count() 메서드를 사용할 수 있습니다. removeAll 메서드를 사용한 후에도 객체가 남아있다면 count 메서드는 0이 아닌 값을 반환합니다.

    #hostingforum.kr
    php
    
    $storage = new SplObjectStorage();
    
    $storage->attach(new stdClass());
    
    $storage->attach(new stdClass());
    
    
    
    $storage->removeAll();
    
    
    
    var_dump($storage->count()); // 0
    
    

    2025-08-02 03:04

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 41,000건 / 8 페이지

검색

게시물 검색