$val) { if (\is_string($key)) { $key = '\'' . \str_replace('\'', '\\\'', $key) . '\''; } $stringify .= str_repeat(' ', $depth * 4) . $key . ' => ' . self::parseVariable($val, $depth + 1) . ',' . "\n"; } return $stringify . str_repeat(' ', ($depth - 1) * 4) . ']'; } /** * Serialize value. * * @param mixed $value Value to serialzie * @param int $depth Array depth * * @return string * * @since 1.0.0 */ public static function parseVariable($value, int $depth = 1) : string { if (\is_array($value)) { return ArrayParser::serializeArray($value, $depth); } elseif (\is_string($value)) { return '\'' . \str_replace('\'', '\\\'', $value) . '\''; } elseif (\is_bool($value)) { return $value ? 'true' : 'false'; } elseif ($value === null) { return 'null'; } elseif (\is_scalar($value)) { return (string) $value; } elseif ($value instanceof \Serializable) { return self::parseVariable($value->serialize()); } elseif ($value instanceof \JsonSerializable) { return self::parseVariable($value->jsonSerialize()); } else { throw new \UnexpectedValueException(); } } }