@param \stdClass $object

@return array
964238
public static function stdClassToArray(\stdClass $object)
    {
        $object = (array) $object;
        foreach ($object as &$value) {
            if ($value instanceof \stdClass) {
                $value = self::stdClassToArray($value);
                continue;
            }
            if (is_array($value)) {
                foreach ($value as &$arrayValue) {
                    if ($arrayValue instanceof \stdClass) {
                        $arrayValue = self::stdClassToArray($arrayValue);
                        continue;
                    }
                }
            }
        }

        return $object;
    }
1185101
public static function getClassAnnotations($object)
	{
		$classReflection = new \ReflectionClass($object);
		$docBlock = $classReflection->getDocComment();
		$lines = explode("\n", $docBlock);
		$annotations = array();
		foreach ($lines as $line)
		{
			if (preg_match('~^(((\s*\*)|/\*\*)\s*@)(?<annotationName>[^\s]+)\s+(?<annotationValue>.*)~', $line, $matches))
			{
				$annotations[$matches['annotationName']][] = $matches['annotationValue'];
			}
		}
		return $annotations;
	}
1277971
public static function toArray( $object )
    {
        if ( is_object( $object ) )
        {
            return get_object_vars( $object );
        }

        if ( is_array( $object ) )
        {
            return array_map(
                array(
                    __CLASS__,
                    'toArray'
                ),
                $object
            );
        }

        // Return array
        return $object;
    }
563078
public static function objectArray($object)
    {
        if (is_object($object)) {
            $reflectionClass = new \ReflectionClass(get_class($object));
            $array = [];
            foreach ($reflectionClass->getProperties() as $property) {
                $property->setAccessible(true);
                $array[$property->getName()] = $property->getValue($object);
                $property->setAccessible(false);
            }

            //If above method failed? try, this one.
            $array = (empty($array)) ? json_decode(json_encode($object), true) : $array;

            return $array;
        }

        return false;
    }
956953
protected function getHintFromObject($object)
    {
        if (!is_object($object)) {
            return array();
        }

        $class = get_class($object);
        $type = array_search($class, $this->types);

        if ($type) {
            return array('@type' => $type);
        }

        return  array('@class' => $class);
    }
61752
protected function getObjectValues(object $object): array
    {
        $class = new ReflectionClass(get_class($object));
        $constructor = $class->getConstructor();
        if ($constructor instanceof ReflectionMethod) {
            foreach ($constructor->getParameters() as $parameter) {
                $name = $parameter->getName();

                $property = $class->getProperty($name);
                $property->setAccessible(true);

                $value = $property->getValue($object);
                if (is_object($value) === true) {
                    $value = $this->getObjectValues($value);
                }

                $data[$name] = $value;
            }
        }

        return $data ?? [];
    }
87381
protected function parseObjectData($class, $object){
        $result = [];
        $reflection = new \ReflectionClass($class);
        foreach ($reflection->getProperties() as $property){
            $propertyName = $property->name;
            $method = 'get'.ucfirst($propertyName);
            $result[$propertyName] = $reflection->hasMethod($method) ? $object->$method() : null;
        }
        return $result;
    }
483700
public static function args($object) : array
    {
        if (!is_object($object)) {
            throw new InvalidArgumentException('Argument must be'
                . ' an object ' . gettype($object) . ' found.');
        }

        $reflector = new ReflectionClass($object);

        $constructor = $reflector->getConstructor();

        if ($constructor instanceof ReflectionMethod) {
            $args = array_column($constructor->getParameters(), 'name');
        } else {
            $args = [];
        }

        return $args;
    }
1113649
public function extract( $object )
    {
        $result = array();
        $type   = $object->paragraph->type;

        $result['paragraph-' . $type] = $this->getParagraphMapper()
                                             ->extract( $object->paragraph );

        $propertyHydrator = $this->getHydrateSimpleProperties();

        foreach ( $object->rules as $key => $rule )
        {
            $result['customize-' . $key] = $propertyHydrator->extract( $rule )
                                                              [ 'properties' ];
        }

        return $result;
    }
295554
private function serializeObject($object, string $className = null)
    {
        if (is_null($className)) {
            $index = array_search($object, $this->references, true);

            if ($index !== false) {
                $this->referencesUsed[] = $index;

                return ['@ref' => $index];
            }

            $this->references[] = $object;
        }

        $data = ['@type' => get_class($object)];

        $reflectionClass = new \ReflectionClass($className ? $className : $object);

        // parent class
        $parent = $reflectionClass->getParentClass();
        if ($parent) {
            $parentData = $this->serializeObject($object, $parent->getName());
            if (count($parentData) > 0) {
                $data = array_merge($data, $parentData);
            }
        }

        // current $object
        foreach ($reflectionClass->getProperties() as $property) {
            $property->setAccessible(true);
            $value = $property->getValue($object);
            $name = $property->getName();

            // for parent class, don't reserialize public & protected properties
            if (isset($data[$name])) {
                continue;
            }

            // optimization: only save value if not the default value
            $defaults = $reflectionClass->getDefaultProperties();
            if (array_key_exists($name, $defaults) && $defaults[$name] === $value) {
                continue;
            }

            $this->serializeValue($name, $value, $data);
        }

        // ugly hack for public undeclared properties and
        // for internal object like datetime that can't be accessed by reflection
        // @see http://news.php.net/php.internals/93826%20view%20original
        if (!$className) {
            foreach (get_object_vars($object) as $key => $value) {
                if (!isset($data[$key])) {
                    $this->serializeValue($key, $value, $data);
                }
            }
        }

        return $data;
    }
73461
static private function objToArray(&$object)
    {
        if (is_object($object) && method_exists($object, '__trace')){
            $arr = $object->__trace();
            if (!is_array($arr)) return $arr;
        }else{
            $arr = (array)$object;
        }
        $result = [];
        while (list ($key, $value) = each($arr)){
            $keys = explode("\0", $key);
            $clear_key = $keys[sizeof($keys) - 1];
            $result[$clear_key] = &$arr[$key];
        }
        return $result;
    }
123689
public function normalize($object) : array
    {
        return $this->asArray ? $this->normalizeAsArray($object) : $this->normalizeAsAttributes($object);
    }
1078544
private function serializeObjectRecursively($object): array
    {
        $reflection = new ReflectionClass($object);
        $properties = $reflection->getProperties();

        $data = [];
        foreach ($properties as $property) {
            $name = $property->getName();

            $property->setAccessible(true);
            $value = $property->getValue($object);
            $property->setAccessible(false);

            $data[$name] = $this->serializeValue($value);
        }

        return [
            'class' => get_class($object),
            'payload' => $data,
        ];
    }
699435
private static function getReflectionProperties($object)
    {
        $class = get_class($object);

        if (!isset(self::$reflectionProperties[$class])) {
            $reflection = new \ReflectionClass($object);
            $reflectionProperties = array_filter($reflection->getProperties(), function($property) {
                // We only need object context properties???
                return !$property->isStatic();
            });
            self::$reflectionProperties[$class] = [];

            foreach ($reflectionProperties as $property) {
                // Is it always necessary?
                $property->setAccessible(true);

                self::$reflectionProperties[$class][$property->getName()] = $property;
            }
        }

        return self::$reflectionProperties[$class];
    }
1302462
protected function createFormDataArray($object)
    {
        return array(
            "label" => $object->getLabel(),
            "title" => $object->getTitleId(),
            "firstname" => $object->getFirstname(),
            "lastname" => $object->getLastname(),
            "address1" => $object->getAddress1(),
            "address2" => $object->getAddress2(),
            "address3" => $object->getAddress3(),
            "zipcode" => $object->getZipcode(),
            "city" => $object->getCity(),
            "country" => $object->getCountryId(),
            "state" => $object->getStateId(),
            "cellphone" => $object->getCellphone(),
            "phone" => $object->getPhone(),
            "company" => $object->getCompany()
        );
    }
1285087
public static function serialize($object) : array
    {
        $serializer = new static();
        $data = $serializer->serializeObject($object);

        if (sizeof($serializer->referencesUsed)) {
            foreach ($serializer->referencesUsed as $index) {
                $data['@references'][$index] = $serializer->references[$index];
            }
        }

        return $data;
    }
260183
public function serialize($object)
    {
        if (!$this->canHandle(get_class($object))) {
            throw new \InvalidArgumentException();
        }

        return [ $object->getTimestamp(), $object->getTimezone() ];
    }