URL::__set()

Sets a URL data via property access.

Table of Contents
  1. Description
  2. Example

Description

URL::__set(string $key, mixed $value): void;

This method will be called when you try to set a property that doesn’t exist in the class. For this class, this method will also normalize certain properties of the URL such as removing the /, ? and # prefix before setting it to the URL object when trying to set the path, query, and hash properties so that the output data will always be consistent.

Example

$url = new URL('http://127.0.0.1');

$url->hash = 'baz';
$url->path = 'foo/bar/baz//';
$url->query = '&foo=bar';

echo $url->path; // Returns `'/foo/bar/baz'`
echo $url; // Returns `'http://127.0.0.1/foo/bar/baz?foo=bar#baz'`

URL::__set()

Sets a URL data via property access.

URL::current()

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