Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130531 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 EE31F1A00BC for ; Thu, 2 Apr 2026 14:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1775139806; bh=yDRo+6UCRiN8Be9NrdmtGSaIwc8kOZ0u/HK1iZQOcxk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SN75x62bZgpgSLKJSMguUq6CTbgcYRDr3RuPiGC4GphjleX4EGP0QOWVxYK8IqrHO Wlg2O0sS9BsT3oggiEVVqbMeXSfcKhwv/FfswiAczEKq8pB1nSYyIx0D2yHruU1bsT V9otMaJ1h1x9PAoEbGaW9vxgDyhiwqrVhDqz4ymGE12Mschwxc+Uk2dIbV9TBOyrLk CZKNm3IJV0gbbi5rwI+F5QU2IJdd4XgaIQELUD1q39SL7jIawLiHg9SgocIfTTZ9Y0 jc/7CdEJL5x+VSa67ewtOaqh4bO899+8xwteXt/r2P+Lpv04PutOb07u/HbOEONgEa WhgQt2p/nGlNA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BB53618006E for ; Thu, 2 Apr 2026 14:23:25 +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=ARC_SIGNED,ARC_VALID,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,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 ; Thu, 2 Apr 2026 14:23:22 +0000 (UTC) Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-38ce0ab821cso1818481fa.0 for ; Thu, 02 Apr 2026 07:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775139796; cv=none; d=google.com; s=arc-20240605; b=UV7jukCvzNr27VJmQj6vNpkYBTvKn96Ez+Nu0Yfj4q4hNskj38CyPox/hioLwBPo0D at7cpmZ+7laaxXUioe2BOp90HUeosXgt05Zp2zlcvXg2ZJ170c1JqG4lVsCD4IScSli6 aiCwoaTs2GNm0McaJuhKxSC2o8Kd9xT26cQ5rSHRn56UO3r8pjEClPknq4Dnh0NxHp3D zonwNMIKmCQ0XCXmgnJpFex/F0h/4Z2Gc5BBws1xOofI/nhgeIcDNdtx0PDHaep+VsTf 85koS/hRXkEyPHZxMGK6pHm7hRP8Or7XxU2bSBtPYM2UQRXpPmX6jL7/RM6q6Y4FW2YF PMYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=yDRo+6UCRiN8Be9NrdmtGSaIwc8kOZ0u/HK1iZQOcxk=; fh=wz6bO2NsVy/6O+sV88BJjGwt7uPgse/0oxXCC0xQFH8=; b=XYGvGVaC+sqm0UVwIZHQATAK6H0u16lWtxb5eNVZmaChRZAcz8clP43nRzmG6SjtL1 5I8uCTAWduLKw9zrOxDLqjU3nWBrfYHoimGDA7BEfpVHAefhReGf569FlV/WPasHIiEv 7kCAlOK1nf4slLvzjeWC8fmRGlmdICRSnMeeASIP0n5bSP+7bX53Mkn8Faric39n5aSY aTWVBEOdfLqEaIlRhgfY+DPmnuQRjE9+/SQTSiUm9HpzMxTLHH6QLKgJxhLGIDC9WV0s LaUgl5IBIOEDq6f/n6lU4J7d3ch6R31HIQB9Xf07pou/wxGets6RQTLo1uYBIJ+OtMw/ m16A==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775139796; x=1775744596; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yDRo+6UCRiN8Be9NrdmtGSaIwc8kOZ0u/HK1iZQOcxk=; b=np9eYtulSrz0hBUyPIIMNn1mRFz7m0ivb9K/TWB4etlDC97izg7v3p4hnzrEP5JrAn FdBxl4GsISnuHtEJE6AfzA1RRHt0KalS0aU1ZuJrvJzruJbwxNBnLg15OwBvZ3q94ydq 1K9R+lyO9BWnGrB6pEE1C9Dbqgf+AHfrazlWlIDjPpi8xreQv7cejz/kWure1knSEgfk NttR3sCVvefrEiWJtZ9webNu2ymc4zOW3nTJUE5aTzDvaYcn5p3naTWHSfup/i0GQhnl 9id+DEPoMP7eACl6NK2nd9JkXrGcMyoSR6ImzZnV487e//sMc/4hxkbuToVkCeryQfHK jxtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775139796; x=1775744596; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=yDRo+6UCRiN8Be9NrdmtGSaIwc8kOZ0u/HK1iZQOcxk=; b=BixeBivEMZOUaPaPLgIynWOT2jz4n5k775CEHeTyaDKE+mjQXxBTYFpGKHgwaQsj9k 1X2uTKvRIe6sDOAwHXpfwOCpIQgFd+9oDX1rW+D2sgUckhlQKNCx9SQciLuYgF8fT6K+ j0npQ5Ay4yrtRgL3QGWjtn6hKf049wI7Cjeiomq//0HvpqHq3ZnaW90+cf18aQAxxSkn 6edUDJ0xKRsErJ6+bMpCAH5Q5MmMrcFCWpQdZtrbrzB0zw5WuM/srhjx/GbXPtbqDLSL cxj1wpPL0WefjGoZOHST38MlkoGmSpiOolJwL7ghDRPndH4n6flgqPMMAdxcCZSDEmcN FajA== X-Gm-Message-State: AOJu0YwHYEpbvhvtuhWE618PFXjkFFvb45U5lKIjMzsnMX4bVnS6wEp1 7378nCVbHQwIOkRDkcbQsT/6OIPA1baQqvakmciFLPVOYpI0wDuoSLOiarPmJ3W23rF0TyQvhBz vtf9J4DLFpGNZ3vgcJnerosh8w/vQ8XM= X-Gm-Gg: ATEYQzy6z4lw+mHwB4DivUvUQbE4zAXWXviXEiEw4kkZ64pvX10hc2U2wQ1xDTQIw+G SuM1DkbT/PggDH/oo20y3h9sQRbO6ThXiProjJxfaQlx1hlefGEgMVfde9R7o1lbGuwxn8sfIN+ jYGdHQAMieWauJk33c8R86TipZjGgRtmWWB4w4XvpodP2aAyUsawZlMSsROyeA8S+F1DfKapW/S +afDUfC+qXd98fzvY6W2IQbeEVLO9GmRehnN4uQ5KCrUg2ya+Hpfgz0nA8vIxLxt8qLVE/3/kqm uwJ4YOvq/U+Oqtnr X-Received: by 2002:a05:6512:1088:b0:5a2:a8ab:ab55 with SMTP id 2adb3069b0e04-5a2c1eec1bdmr3496718e87.1.1775139795585; Thu, 02 Apr 2026 07:23:15 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 2 Apr 2026 09:23:03 -0500 X-Gm-Features: AQROBzBZPQCcCpSgiaNhWXR03V9ef6MEGFcgz5OudJXnr94lHvdD3kSb_fN7POU Message-ID: Subject: Re: [PHP-DEV] RFC proposal: Invokable interface To: Osama Aldemeery Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000f14d61064e7af0f5" From: mweierophinney@gmail.com ("Matthew Weier O'Phinney") --000000000000f14d61064e7af0f5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Mar 29, 2026 at 4:44=E2=80=AFPM Osama Aldemeery wrote: > Hi all, > > I'd like to propose an Invokable interface, the Stringable equivalent for > __invoke(). > > The idea has come up a few times over the years (most recently in the PR > #15492 discussion, where Gina suggested this exact approach) but never ha= d > a concrete implementation. > > I've put one together: https://github.com/php/php-src/pull/21574 > > It follows the Stringable pattern: auto-implemented for any class definin= g > __invoke(), explicitly implementable with enforcement, and covariant to > callable in return type checks. > > I honestly don't feel there's a need for this, as we already have the callable type. It shouldn't matter if the callable is an object defining `__invoke()`, a function, a closure, or a first class callable. If you need to restrict to an object that's invokable, you can do that already via (object&callable). Further, PHPStan, Psalm, PHPCS, and php-cs-fixer all understand annotations around the callable type already to further define the allowed signature (e.g., number and types of arguments, return value). This is a solved problem already. Further, creating an interface for this is hugely difficult, if not impossible, due to the return value associated with the interface, as implementations will inevitably conflict with the Liskov Substitution Principle. If we say "void", you cannot declare an implementation with a return value. If you define mixed, you cannot have a void or never return. --=20 Matthew Weier O'Phinney mweierophinney@gmail.com https://mwop.net/ he/him --000000000000f14d61064e7af0f5 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Sun, Mar 29,= 2026 at 4:44=E2=80=AFPM Osama Aldemeery <aldemeery@gmail.com> wrote:
Hi all,

I'd like to= propose an Invokable interface, the Stringable equivalent for __invoke().<= br>
The idea has come up a few times over the years (most recently in th= e PR #15492 discussion, where Gina suggested this exact approach) but never= had a concrete implementation.

I've put one together:=C2=A0https:/= /github.com/php/php-src/pull/21574

It follows the Stringable pat= tern: auto-implemented for any class defining __invoke(), explicitly implem= entable with enforcement, and covariant to callable in return type checks.<= br>

I honestly don't f= eel there's a need for this, as we already have the callable type. It s= houldn't matter if the callable is an object defining `__invoke()`, a f= unction, a closure, or a first class callable. If you need to restrict to a= n object that's invokable, you can do that already via (object&call= able). Further, PHPStan, Psalm, PHPCS, and php-cs-fixer all understand anno= tations around the callable type already to further define the allowed sign= ature (e.g., number and types of arguments, return value). This is a solved= problem already.

Further, creating an interface f= or this is hugely difficult, if not impossible, due to the return value ass= ociated with the interface, as implementations will inevitably conflict wit= h the Liskov Substitution Principle. If we say "void", you cannot= declare an implementation with a return value. If you define mixed, you ca= nnot have a void or never return.

--
=
he/him
--000000000000f14d61064e7af0f5--