hasProperty($name)) { return false; } $reflectionProperty = $reflectionClass->getProperty($name); if (!($accessible = $reflectionProperty->isPublic())) { $reflectionProperty->setAccessible(true); } $reflectionProperty->setValue($obj, $value); if (!$accessible) { $reflectionProperty->setAccessible(false); } return true; } /** * Get private object member * * @param object||string $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($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; } }