Recurse through non scalars turning them into arrays, just returns scalars as is.
@param $object
@return mixed
321804
protected function recurseToArray($object)
    {
        if (is_scalar($object)) {
            return $object;
        }
        $array = (array)$object;
        foreach ($array as &$value) {
            if (!is_scalar(($value))) {
                $value = $this->recurseToArray($value);
                continue;
            }
        }
        return $array;
    }
1328962
public function extract($object): array
    {
        if (!is_object($object)) {
            throw new RuntimeException(
                sprintf('%s expects the provided $object to be a PHP object', __METHOD__)
            );
        }

        return (function (): array {
            return get_object_vars($this);
        })->call($object);
    }
63117
public function toArray($object)
    {
        $result = array();
        $className = $this->getFullClassName($object);
        $metadata = $this->metadataFactory->getMetadataForClass($className);
        foreach ($metadata->getProperties() as $property) {
            if (!$property->isExpose() || $this->propertySkipper->shouldSkip($property)) {
                continue;
            }

            $value = $this->exposeValue($object, $property);
            $value = $this->handleValue($value, $property, self::DIRECTION_SERIALIZE);

            if ($property->isNullSkipped() && $value === null) {
                continue;
            }

            $result[$property->getSerializedName()] = $value;
        }

        return $result;
    }
1147984
public static function toArray($object)
	{
		if(is_array($object))
			return $object;
		elseif(!is_object($object))
			return (array) $object;
		elseif ($object instanceof IlluminateCollection)
			return $object->all();
		elseif ($object instanceof IlluminateArrayable)
			return $object->toArray();
		elseif(method_exists($object, '__toString'))
			return [$object];
		elseif ($object instanceof IlluminateJsonable)
			return (array) json_decode($object->toJson(), true);
		elseif ($object instanceof JsonSerializable)
			return (array) $object->jsonSerialize();
		elseif ($object instanceof Traversable)
			return iterator_to_array($object);
		else
			return (array) $object;
	}
987704
private function buildDataFromObject($object)
    {
        $result = array();

        $stack = new \SplStack();
        $stack->push($object);

        while (!$stack->isEmpty()) {
            $current = $stack->pop();
            if (is_object($current)) {
                array_push($result, $current);
            }

            foreach ($this->getDataFromItem($current) as $propertyName => $propertyValue) {
                if (is_object($propertyValue) || is_array($propertyValue)) {
                    $stack->push($propertyValue);
                }
            }
        }

        return $result;
    }
340707
public function getUnmappedArray(DataObject $object)
    {
        $output = [];

        foreach ($this->mapping as $unmappedField => $mappedField) {
            if (strpos($mappedField, ':') !== false) {
                list($mappedField, $modifier) = explode(':', $mappedField);
            }

            $output[$unmappedField] = $object->{$mappedField};
        }

        return $output;
    }
1110283
public function extract($object)
    {
        $data = parent::extract($object);

        foreach ($this->getFreeValuesKeys() as $key) {
            $data[$key] = $object->get($key);
        }

        return $data;
    }
1162490
public function extract($object)
    {
        $return = array();
        foreach ($object as $profile) {
            $return[strtolower($profile->getName())] = $profile->getData();
        }
        return $return;
    }
934640
public function objectToArray($object)
    {
        if (!is_object($object) && !is_array($object)) {
            return $object;
        }
        if (is_object($object)) {
            $object = get_object_vars($object);
        }

        return array_map([get_class(), 'objectToArray'], $object);
    }
1116974
public static function toArray($object)
    {
        $object = AnConfig::unbox($object);

        if (is($object, 'AnObjectArray') || is($object, 'AnObjectSet')) {
            return $object->toArray();
        }

        return (array) $object;
    }
1472
public function get($object)
    {
        $hash = spl_object_hash($object);

        if (isset($this->data[$hash])) {
            return $this->data[$hash];
        }

        return null;
    }
951747
private static function toArray($object)
    {
        $json = array();
        $props = self::getProperties($object);
        foreach ($props as $key => $value) {
            $check_references = explode("_", $key);
            $getter = "";
            if (count($check_references) > 0) {
                foreach ($check_references as $reference) {
                    $getter .= ucfirst($reference);
                }
            } else {
                $getter = ucfirst($key);
            }
            $getter = "get" . $getter;

            if (!method_exists($object, $getter)) {
                continue;
            }
            $key = self::toSnakeCase($key);
            $value = $object->$getter();
            if (self::isNull($value)) {
                continue;
            }
            if ($value instanceof \Iterator) {
                $value = iterator_to_array($value);
            }
            if (is_object($value)) {
                $json[$key] = self::toArray($value);
            } else {
                if (is_array($value)) {
                    $json[$key] = array();
                    if (ArrayHelper::isAssoc($value)) {
                        foreach ($value as $k => $anObject) {
                            if (is_object($anObject)) {
                                $json[$key][$k] = self::toArray($anObject);
                            } else {
                                $json[$key][$k] = $anObject;
                            }
                        }
                    } else {
                        foreach ($value as $anObject) {
                            if (is_object($anObject)) {
                                $json[$key][] = self::toArray($anObject);
                            } else {
                                $json[$key][] = $anObject;
                            }
                        }
                    }
                } else {
                    $json[$key] = $value;
                }
            }
        }

        return $json;
    }
922030
protected function objectToArray($object)
    {
        $class = get_class($object);
        $info = new \ReflectionClass($object);

        $this->commentMap[$class] = [];

        $methods = [];
        foreach ($info->getMethods() as $method) {
            if (!$method->isPublic()) {
                continue; // Only public
            }
            if ($method->class != $class) {
                continue; // Only locals
            }
            $name = $method->getName();
            if (in_array($name, $this->blockMethods)) {
                continue; // Blocked methods
            }
            if (preg_match('/^on[A-Z]{1}[\w+]*$/', $name)) {
                continue; // AJAX methods
            }
            if (preg_match('/^get[A-Z]{1}[\w+]*Options$/', $name)) {
                continue; // getSomethingOptions
            }
            if (substr($name, 0, 1) == '_') {
                continue; // Magic/hidden method
            }
            $name .= '()';
            $methods[$name] = '___METHOD___|'.$name;
            $this->commentMap[$name] = $this->evalDocBlock($method);
        }

        $vars = [];
        foreach ($info->getProperties() as $property) {
            if ($property->isStatic()) {
                continue; // Only non-static
            }
            if (!$property->isPublic()) {
                continue; // Only public
            }
            if ($property->class != $class) {
                continue; // Only locals
            }
            $name = $property->getName();
            $vars[$name] = $object->{$name};
            $this->commentMap[$name] = $this->evalDocBlock($property);
        }

        return $methods + $vars;
    }
207618
public function extract($object)
    {
        $data = ['name' => $object->getNormalizedName()];
        if ($object->hasParent()) {
            $data['source'] = strval($object->getParent()->getNormalizedName());
        }
        return $data;
    }
317130
public static function ObjectAsArray($Object) {
      if (!is_object($Object))
         return $Object;

      $Return = array();
      foreach(get_object_vars($Object) as $Property => $Value) {
         $Return[$Property] = $Value;
      }
      return $Return;
   }
1141064
public static function object_to_array($obj)
	{
		//$_arr = is_object($obj) ? get_object_vars($obj) : $obj;
		if(is_object($obj) || is_array($obj)){
			if(is_object($obj)){
				$_arr = get_object_vars($obj);
			}else{
				$_arr = $obj;
			}
			foreach ($_arr as $key => $val)
			{
				$val = (is_array($val) || is_object($val)) ? self::object_to_array($val) : $val;
				$arr[$key] = $val;
			}
			return $arr;
		}else{
			return $obj;
		}
		
	}
440687
public static function convert($object, $recursive = false)
    {
        if ($object instanceof \Traversable) {
            $array = iterator_to_array($object);
        } elseif (method_exists($object, 'toArray')) {
            $array = $object->toArray();
        } elseif (method_exists($object, 'asArray')) {
            $array = $object->toArray();
        } elseif (method_exists($object, 'as_array')) {
            $array = $object->toArray();
        } elseif (method_exists($object, 'getArrayCopy')) {
            $array = $object->toArray();
        } elseif (is_object($object)) {
            $array = get_object_vars($object);
        } else {
            $array = (array) $object;
        }

        if (!$recursive) {
            return $array;
        }

        $data = [];
        foreach ($array as $key => $value) {
            $data[$key] = is_object($value)
                ? self::convert($value, $recursive)
                : $value;
        }

        return $data;
    }