Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129140 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 45C231A00BC for ; Fri, 7 Nov 2025 20:30:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762547462; bh=xbUYbq3IgUMFhQzIYIwedip0hfADjz7dcY7bGtW9ou0=; h=From:Date:Subject:To:From; b=enf0WR1SN1Q9VAkxyQAlUFZVOalCbYQ/niRaZ7njYNO8enn9cXH1wP1HQIia8TppR 0AhbifI3Dg5i4BHixvbUmWfj/umi5/A7Q25aXsB1z+m4YEaDHSKHKJngTUlXuV685c 4I3Yebc+MC20kmB1xtOsDL6J9MwW/VEMXy/PfBP9Too6T6BJQqgbFV21gSSHgufcXC 3Uco/+Hkpi2NXKoqIspnSJQKwFACi+TdPjmUya/+uoXINhBIbL9HPChYIL4H9vNqdP qV/5c9tZ2P9pWsdo9efJYuBnXZh2LaIFFo9LVUD091VKCgecKhGd7oYtSvRC3lBhoK M0YWtIZ3grTLA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BBAE6180087 for ; Fri, 7 Nov 2025 20:30:58 +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_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) (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 20:30:58 +0000 (UTC) Received: by mail-io1-f47.google.com with SMTP id ca18e2360f4ac-93e7d3648a8so42864539f.2 for ; Fri, 07 Nov 2025 12:30:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762547452; x=1763152252; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=H2iGaqT4YkkXjqxK6jojbC2nCa97ZVEX279ZiXQBJaU=; b=fx3HiRfcE5WQhlLFa/4aC1rRhm/eLiL8m9+xQMGhpxW8dU+H2ehgbPpCaw1GwEdLkY bmMlF37l1MnUgF9w25H50uLeOnko0oaLUrF2E4vK73oeCmouVkimh0LJqN9re1heJhxg q72an4l2aoTokXDVI8JCfjjrHvtDVj22eC0VLzbj4xta4eNlCiKLowbv/ysgXjpOm6Nq IYbr6DWzQ77/LwbFSkyKkazJHS6QWHe9LH5LF8TtBNJKKsWny11ifqUYSDFQbJhFVpSi BAswo10dimSQBFfkIpAS5cZbi36vdzafKCkPoTwMTrl4gPiPyu9YzUYJkaIIZ5+95OS8 hp0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762547452; x=1763152252; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H2iGaqT4YkkXjqxK6jojbC2nCa97ZVEX279ZiXQBJaU=; b=Atnc3w2T66yesKy92Rblis4mkUG6Ur3wHiJzt32z7puRklKBzTPHmZTZjiEoV0RLtP 3FvuXvinSf+guhjO5gQFqJFZjtRPv6OX2V/m7CjaBUh81dY1sDlPJ/O07kAt2tDvcxUk iRqul6BQmxueBCmjv8ipOO+hY+5BTiBhDSDHj2C8u3MyzLmJQ1JDDCEzgGLpj8L3A7xZ Aw4xhzlGwsUUjCcUyvlGpiXyrFAR8w2L0FSGEvGVWmGoBhqjw6QLkc+F1XEj1/8hCO2o ET2OrasEzhUgP7c2iCZUTdFd8xsIE0d1UT33+WHWYkbVBmGlgv2BGde8R/IuXHmlwIjr vb3g== X-Gm-Message-State: AOJu0YyINcgWjNnJKfAcZxo/7rzvX8/QoPA14pvLHwPmee/s8h1k44v4 7I39rU56N1cRY9C7gR6JZVyj7HlIOIXF3Zyx4kA+GEJdxc+lofqb4qWq7bw4I5ZPN+1LwJIt9jI qaBOB0K6vbQjDenhtLHrbkz05zvVBPIdGu6QL X-Gm-Gg: ASbGncubLGsWVK0CS3wQEO3C9kgrVNf7+BlgWugwn5XhdsrbSMTuQnsm6ltx1AqAQka kC3MsSt1g/Ja/DzoHReBVRlbrEh+VHlX6HslucX+mkmqZ2gEUlQRPg0nkQztF14g8aICFHXbJ7s Ji6+vjLcQi0JiXZdJlTPWtsqThdxMX0Q2VWebpTcCxxzRLFVgC+zn8/KEfaVbRuvfH0modpkEwn mfkAt2gJYTASQaZ8iKBFnJjhKIveUl8dTtU3u0PEF3Dq9VRr7ZaSYxhZ5AF82o= X-Google-Smtp-Source: AGHT+IEmYIoLxTMJfa2lnpNPXwqHxbf608/Zan4PAJ5XAboF3mK2M7jS+2+k9+z7JOiWic/yISMRCIptlWo+Ug3zJXA= X-Received: by 2002:a05:6602:15d0:b0:945:abea:9f67 with SMTP id ca18e2360f4ac-94895faec1dmr81608039f.5.1762547452411; Fri, 07 Nov 2025 12:30:52 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Fri, 7 Nov 2025 12:30:41 -0800 X-Gm-Features: AWmQ_bn2A-oLAU8Z6jWsy8qK8gmcgK2aZhDmcC7Dn69vW815ouT1fn0_I4gFsis Message-ID: Subject: [PHP-DEV] Re: Pre-RFC proposal: opt-in implicit interfaces / structural typing To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000cd02c50643070e4b" From: malone.spencer@gmail.com (Spencer Malone) --000000000000cd02c50643070e4b Content-Type: text/plain; charset="UTF-8" Apologies for the top post, I'll... have to get used to that. > 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. I'm not sure I understand why the value on this is low without extension functions or why we would need the ability to opt-out. In my day to day, I saw this most commonly being utilized for: 1) I'm working with a class that is probably oversized, but I only care about a thin part of the functionality, but I don't have a clear way to add an interface to that class which defines the contract I need. Using an implied interface in this case helps me thin out the contract to what I need, and that makes testing much easier as I can mock only those relevant functions. This would be resolvable with the original class being better designed, but that's not always an option. On the testing side this is kind of made easier with partial mocks, but those can trigger all sorts of side effects that aren't much fun to work with in my experience. 2) The joining of common interfaces for easier introduction of interoperable interfaces, thinking about PSR-11 not tackling the configuration of entities, or how some of the interfaces look on the symfony cache packages. 3) Clearer definition of "duck-typing" like behaviors into the function signature. This is stuff we already see in PHP (`if (method_exists()`), but to me it would improve clarity if these requirements were in the parameter and property definitions, instead of in the function body. All 3 of these (at least to me) seem improved with this path and high value, but I'm worried I may be missing something. To me in these cases, if someone bumps into mistaken typing, that's generally on the caller. Explicit interfaces do guarantee that anyone opting into that contract is doing it for the intended reasons, but if you're working with an implicit interface it becomes the function caller's responsibility to ensure they are making wise decisions on what gets passed in. I don't think this is a new problem set since it exists with the current duck typing patterns, all we've done is more clearly defined our expectations on what functions exist without a lot of manual `method_exists`/`property_exists` - Spencer --000000000000cd02c50643070e4b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Apologies for the top post, I'll..= . have to get used=C2=A0to that.

> I could see impli= cit interfaces working in conjunction with extension functions, if we can f= igure those out.=C2=A0 I'm not sure if they offer much value without th= em, given the state of PHP.=C2=A0 It would basically mean you have to opt-o= ut of a type rather than opt-in, as now.=C2=A0 That could get... weird.
=

I'm not sure I understand why the value on this is = low without extension functions or why we would need the ability to opt-out= . In my day to day, I saw this most commonly being utilized for:
=
1) I'm working with a class that is probably oversized, = but I only care about a thin part of the functionality, but I don't hav= e a clear way to add an interface to that class which=C2=A0defines the cont= ract I need. Using an implied interface in this case helps me thin out the = contract to what I need, and that makes testing much easier as I can mock o= nly those relevant functions. This would be resolvable with the original cl= ass being better designed, but that's not always an option. On the test= ing side this is kind of made easier with partial mocks, but those can trig= ger all sorts of side effects that aren't much fun to work with in my e= xperience.

2) The joining of common interfaces for= easier introduction of interoperable=C2=A0interfaces, thinking about PSR-1= 1 not tackling the configuration of entities, or how some of the interfaces= look on the symfony cache packages.

3) Clearer de= finition of "duck-typing" like behaviors into the function signat= ure. This is stuff we already see in PHP (`if (method_exists(<bla bla>= ;)`), but to me it would improve clarity if these requirements were in the = parameter and property definitions, instead of in the function body.
<= div>
All 3 of these (at least to me) seem improved with this = path and high value, but I'm worried I may be missing something.
<= div>
To me in these cases, if someone bumps into mistaken typ= ing, that's generally on the caller. Explicit interfaces do guarantee t= hat anyone opting into that contract is doing it for the intended reasons, = but if you're working with an implicit interface it becomes the functio= n caller's responsibility to ensure they are making wise decisions on w= hat gets passed in. I don't think this is a new problem set=C2=A0since = it exists with the current duck typing patterns, all we've done is more= clearly defined our expectations on what functions exist without a lot of = manual `method_exists`/`property_exists`

- Spencer=
--000000000000cd02c50643070e4b--