
SplObjectStorage::unserialize 메소드는 저장된 객체를 unserialize 하는 데 사용됩니다. 하지만 이 메소드는 다음과 같은 형태의 오류를 발생시킬 수 있습니다.
- 저장된 객체가 삭제된 경우: 이 경우 SplObjectStorage::unserialize 메소드는 NULL을 반환합니다.
- 저장된 객체가 unserialize 할 수 없는 경우: 이 경우 SplObjectStorage::unserialize 메소드는 Exception을 발생시킵니다.
위 코드의 실행 결과를 예상해 보겠습니다.
- `$storage->unserialize(serialize($storage));` 부분에서 SplObjectStorage::unserialize 메소드는 저장된 객체를 unserialize 하기 때문에 `$storage` 객체와 동일한 객체를 반환합니다.
- `$serialized` 변수가 `$obj`와 동일한 객체 인지 확인하고 싶다면, `$serialized` 변수를 unserialize 한 후, `$obj`와 비교하면 됩니다. 예를 들어, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$storage = new SplObjectStorage();
$obj = new stdClass();
$storage->attach($obj);
$serialized = $storage->unserialize(serialize($storage));
$unserialized = unserialize(serialize($serialized));
print_r($obj === $unserialized); // true
위 코드의 실행 결과는 true가 나올 것입니다.
2025-05-15 16:00