Hi

Am 2025-02-24 15:05, schrieb Hammed Ajao:
What's wrong with declaring all the methods as final eg.
https://github.com/lnear-dev/ada-url/blob/main/ada_url.stub.php

It is not possible to construct a subclass in a generic fashion, because you don't know the constructor’s signature and you also don’t know if it added some properties with a certain semantic. That means that the `with*()`ers are unable to return an instance of the subclass, leading to confusing behavior in cases like these:

    final class HttpUrl extends \Uri\Rfc3986\Uri {
public function __construct(string $uri, public readonly bool $allowInsecure) {
            parent::__construct($uri);

            if ($this->getScheme() !== 'https') {
                if ($allowInsecure) {
                   if ($this->getScheme() !== 'http') {
throw new ValueError('Scheme must be https or http');
                   }
                } else {
                    throw new ValueError('Scheme must be https');
                }
            }
        }
    }

    $httpUrl = (new HttpUrl('https://example.com'))->withPath('/foo');
    get_class($httpUrl); // \Uri\Rfc3986\Uri

Best regards
Tim Düsterhus

Reply via email to