Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129138 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id CBF1D1A00BC for ; Fri, 7 Nov 2025 19:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762543735; bh=Wa8+sp6enA1cAkWlMysZ526p2bZOEMdXD/wdhKUJqJk=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=T7T3Cu8S5PS/6Exz6/GQQDergZBJ/Nu51aG0AQFs8ll33nf+fkmtbr5nbJIWW4GZv ORNTunke68VqTGoCggYZQU2/Lxy7vD+GgOxkCx+r6nMDi8nQ1Ev9queQM/F2brp6Xj 6OMY+/IAti3MKeKcF5cyF79nGRWOQcE1GA3jKybehkKpP6u4BzdQaIgzp1Bc8231KC OEfQbZF+3ANlm7rhw4gF/oIJPewDHef6XUkUq18Vc3/YBql7fLuMIKwPl6r2grTIFG 3EMjRsPc3h9efk/BKQW3cKAvHX+8wKd+eMPFHmaz0NMqp3D+Ijkg7qIIMoGI21ItAf jWeDrzuBrOOdw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 83F66180086 for ; Fri, 7 Nov 2025 19:28:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from nebula.zort.net (nebula.zort.net [96.241.205.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 7 Nov 2025 19:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zort.net; s=zort; t=1762543728; bh=Wa8+sp6enA1cAkWlMysZ526p2bZOEMdXD/wdhKUJqJk=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=SQOE16oIWqnpakTAVN943KIn4cuBxeBmXAuGsp+lyBUmhc98e3kW2ZAKpcO39tCWb vNZJPhRa4U+FPMUybqC1z+Ep1r5HG3/GklxMLyIHjbAnl/+kRqVCAay6ra3CpHG1co ZCA3brg/pzhuaMCg6LpXqPQAmxk0TYqNn7OKvNAc= Received: from smtpclient.apple (pulsar.zort.net [96.241.205.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by nebula.zort.net (Postfix) with ESMTPSA id 749971300509; Fri, 7 Nov 2025 14:28:48 -0500 (EST) Content-Type: text/plain; charset=us-ascii Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: [PHP-DEV] Pre-RFC proposal: opt-in implicit interfaces / structural typing In-Reply-To: <611bb7bf-6cb1-4fa7-bab0-9d3bdc355989@app.fastmail.com> Date: Fri, 7 Nov 2025 14:28:38 -0500 Cc: php internals , Spencer Malone Content-Transfer-Encoding: quoted-printable Message-ID: <467CA241-4457-4058-96D8-9CE721F22198@zort.net> References: <83BA9524-6095-4C8B-8F82-B2F344C4D062@zort.net> <611bb7bf-6cb1-4fa7-bab0-9d3bdc355989@app.fastmail.com> To: Larry Garfield X-Mailer: Apple Mail (2.3826.700.81) From: jbafford@zort.net (John Bafford) > On Nov 7, 2025, at 13:54, Larry Garfield = wrote: >=20 > Languages with implicit interfaces like Go also go (no pun intended) = "all in" on it. All methods on an object are defined externally, = possibly not even in the same file. The whole standard lib was built on = that model from the ground up. That's not the case in PHP. =20 >=20 > I've been pondering extension functions for some time, and have kicked = the idea around with John before. (I would do it as functions, a la = Kotlin, not as a secondary class, like Rust.) Autoloading and = efficiently determining that you need to call an extension are the key = stumbling blocks (though my stance on autoloading at this point is = "we've got opcache enabled 100% of the time, we have things like = FrankenPHP, just front-load the file and move on with your life). =20 >=20 > I could see implicit interfaces working in conjunction with extension = functions, if we can figure those out. I'm not sure if they offer much = value without them, given the state of PHP. It would basically mean you = have to opt-out of a type rather than opt-in, as now. That could get... = weird. >=20 > --Larry Garfield Opting out would both be weird, and from a practical standpoint, is = unreasonable to ask of userspace developers. For correctness, every potential implicit interface match would have to = be explicitly declared as non-comforming in order to be correct. It's = both very noisy and does not scale. =46rom a library perspective, it's = impossible: a library class can't possibly declare all the possible = does_not_implement conformances because the entire universe of = interfaces that might overlap its shape can't be known. A pathological example might look something like: ``` class DeckOfCards implements Shuffleable, \Deck\Drawable // We don't actually import any of these, but we have to = explicitly deny them because otherwise it will cause problems in = end-user code does_not_implement \FooGraphics\Drawable, \BarGraphics\Drawable, = \ZodGraphics\Drawable, \GameEngine\TieInterface, = \BarGameEngine\DeckDrawable, \Vehicle\Drawable {...} ``` There's also a problem point with any code that calls = `get_declared_classes()` and filters by `instanceof SomeInterface`. Now = all that code is potentially broken (if implicit conformances don't meet = contractual requirements). Would we need to add an = implicit/explicit/either option to `is_a()` to make userspace able to = correctly reason about types? Are there other cases where implicit = conformance needs to be treated differently than explicit conformance? Importing a package that has an implicit type would basically have to = come with a warning, "don't make your classes look like this interface = or else things might break". And I'm sure someone would also find a creative way to abuse the trivial = case, `implicit interface AnyObject {}`. -John