hasProperty($name)) { return false; } $reflectionProperty = $reflectionClass->getProperty($name); if (!($accessible = $reflectionProperty->isPublic())) { $reflectionProperty->setAccessible(true); } if (\is_string($obj)) { $reflectionProperty->setValue($value); } elseif (\is_object($obj)) { $reflectionProperty->setValue($obj, $value); } if (!$accessible) { $reflectionProperty->setAccessible(false); } return true; } /** * Get private object member * * @param object $obj Object to read * @param string $name Member name to read * * @return mixed Returns the member variable value * * @since 1.0.0 */ public static function getMember(object $obj, string $name) { $reflectionClass = new \ReflectionClass(\is_string($obj) ? $obj : \get_class($obj)); if (!$reflectionClass->hasProperty($name)) { return null; } $reflectionProperty = $reflectionClass->getProperty($name); if (!($accessible = $reflectionProperty->isPublic())) { $reflectionProperty->setAccessible(true); } $value = $reflectionProperty->getValue($obj); if (!$accessible) { $reflectionProperty->setAccessible(false); } return $value; } }