
GMP::__unserialize() 함수를 사용하여 unserialize 한 후 GMP 객체의 속성에 접근하는 방법은 다음과 같습니다.
GMP 객체의 속성은 배열 형태로 저장되므로, array_key_first() 함수를 사용하여 첫 번째 키를 얻어내고, foreach 문을 사용하여 모든 키를 얻어낼 수 있습니다.
예를 들어, 다음 코드는 다음과 같이 수정할 수 있습니다.
#hostingforum.kr
php
$gmp_var = GMP::__unserialize('a:1:{i:1;s:5:"hello";}');
$attributes = array_keys((array)$gmp_var);
foreach ($attributes as $attribute) {
echo $gmp_var->$attribute . "n";
}
또는, 다음 코드를 사용할 수도 있습니다.
#hostingforum.kr
php
$gmp_var = GMP::__unserialize('a:1:{i:1;s:5:"hello";}');
$reflectionClass = new ReflectionClass($gmp_var);
$properties = $reflectionClass->getProperties(ReflectionProperty::IS_PUBLIC);
foreach ($properties as $property) {
$property->setAccessible(true);
echo $property->getValue($gmp_var) . "n";
}
위 코드는 GMP 객체의 속성을 모두 출력합니다.
2025-04-29 23:28