URL::jsonSerialize()

Returns the URL data to be serialized as JSON.

Table of Contents
  1. Description
  2. Example

Description

URL::jsonSerialize(): mixed;

This method is a requirement to be able to implement the JsonSerializable interface and aims to make the data convertable to JSON. You won’t use this method directly, the json_encode() function will call this method automatically.

Example

$url = new URL('http://127.0.0.1:8080/foo/bar/baz?foo=bar#baz');

$test = json_encode($url); // Returns `{"hash":"baz","host":"127.0.0.1","path":"foo/bar/baz","port":8080,"protocol":"http","query":"foo=bar"}`

URL::current()

Returns the full URL address along with its query and hash.

URL::jsonSerialize()

Returns the URL data to be serialized as JSON.