Cannot modify readonly object of class %s

Description

It is possible to call the constructor on an existing object, after its creation. In the case of the Url objects, the underlying URL string is readonly, and the renewed call to the constructor is not possible.

Example

<?php

$uri = new Uri\WhatWg\Url('https://www.php.net/');
$uri->__construct('https://php.net/');

?>

Literal Examples

  • Cannot modify readonly object of class UriWhatWgUrl

Solutions

  • Create a new Url object, instead of updating the existing one.