Re: [RFC] [Discussion] Add WHATWG compliant URL parsing API

From: Date: Mon, 24 Feb 2025 16:22:39 +0000
Subject: Re: [RFC] [Discussion] Add WHATWG compliant URL parsing API
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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

Thread (152 messages)

« previous php.internals (#126498) next »