Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115118 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90968 invoked from network); 24 Jun 2021 14:19:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jun 2021 14:19:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2F2491804CC for ; Thu, 24 Jun 2021 07:38:23 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 24 Jun 2021 07:38:22 -0700 (PDT) Received: by mail-ed1-f45.google.com with SMTP id s15so8830873edt.13 for ; Thu, 24 Jun 2021 07:38:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=xPHdqkSGhkhSPxuooS6nSMKzgO1xX7Mms6Y/On4EHus=; b=jV/fxLTj4urKbRqJ/ZJH7QKiXDbHB/Etj1F2uyp1rhtIYG+xM0DXY1sQ95M109v5Vq mqvN3GBQ+ZJmgbmNyRI/MQoyxUGd/LgNhHl9pN4aot0gdMSwrYAl/q9uhlpR9549pvFG 7xU8PotX/JnDTR/2bbd8a7m8qmsxewn0g852+pwCM5AwU0iWHo02TrLquPZZINM37I5X Q+OvBBu3zPoD6Q0YKqZ8RvIuPr+6pjz6WEyl7jpIl9ZiNrQsK9rCj81FfPHu1MQQHw1Q n3BgjGewT9W7BKEuR8Oj63yrLiJMnR0o+RH9NBCTfWCo4Cnicqunwszt+L9B9TSTAT2K lf0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=xPHdqkSGhkhSPxuooS6nSMKzgO1xX7Mms6Y/On4EHus=; b=VAivZatNP/AjwSn6sQ5aDvq9mZmcok8r3oss/SwOSqQwstRlN8eQG6JWXNxT7vb4qn ihNIKg4wF9R0Oi0ovRMHZBtKNpmIDDYae90LjJ6dvoF/sibseBzumjmIXC4UewyYeSur tmlo7abE6GEmfdorChgWCVI0d/TEQdPs85nj5Q4HTQc5sCd5lzn6QlEi0l06o46Z8kFD 4kNdUcrPrMc/Yf0cxla4teh7RygwWxd5AflqiKBu4vcdhDtYiIynNwL9z/GJeC1akN5G 7fMVG8UHv15eOtWYlXaJCI1kqz/I7UP+nZ9WaXDB1IybjCCsQlPVDebMRxKXojuuUwG6 rA1w== X-Gm-Message-State: AOAM530Gi3s3CDGvMWFTW3nm17Z+SrrP6+w63FGETefyBIH+KFRHnYtJ LGURErNa2QRfS8cQ65FzavbeV3tM3DI= X-Google-Smtp-Source: ABdhPJy8SHPv1XzPvFA2ZJkCj3LTq31uLH5w4/JFKOe/NM/VDFA7m7MiPmncRBODUn3Xklt6BhBbQw== X-Received: by 2002:a05:6402:158c:: with SMTP id c12mr7408662edv.335.1624545501339; Thu, 24 Jun 2021 07:38:21 -0700 (PDT) Received: from claude.fritz.box ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id v5sm2040030edt.55.2021.06.24.07.38.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Jun 2021 07:38:20 -0700 (PDT) Message-ID: <81EDE991-60C8-4DF8-9D1E-1B2BAE144829@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_0BE5AA7E-A3FF-4DE3-8F3A-D36BE46907BB" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Date: Thu, 24 Jun 2021 16:38:19 +0200 In-Reply-To: Cc: internals@lists.php.net To: =?utf-8?B?0JTQvNC40YLRgNC40Lkg0JXQu9C40YHQtdC10LI=?= References: X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] Checking that Closure is static From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_0BE5AA7E-A3FF-4DE3-8F3A-D36BE46907BB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 18 juin 2021 =C3=A0 16:35, =D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9= =D0=95=D0=BB=D0=B8=D1=81=D0=B5=D0=B5=D0=B2 a = =C3=A9crit : >=20 > Hello! When I use a static anonymous function as an HTTP-action in > some frameworks like: >=20 > $app =3D new App(); > $app->get('/', static function () { > return new Response('Hello!); > }) >=20 > I get a warning "Cannot bind an instance to a static closure" in every > $closure->bind($container) call inside of the framework. >=20 > But right now I cannot prevent this warning because there is no native > way to check that closure is static before calling the bind method. I > can only suppress the warning with @ or set/restore_error_handler > pair. >=20 > So I propose to add a method like Closure::isStatic (or > Closure::canBeBound, etc.) for ability of manual checking it before > bind call: >=20 > if (!$closure->isStatic()) { > $closure->bind($object); > } >=20 > The method can contain simple statement: >=20 > return func->common.fn_flags & ZEND_ACC_STATIC; >=20 > It will be helpful if somebody needs to support dynamic and static > callables both without warnings. >=20 > -- Best, Dmitry I think that the Warning should be removed entirely, and the `bindTo()` = method should be a no-op when applied to a static closure. That the closure is implemented as static, or as non-static without = actually using `$this`, is an implementation detail that the user of the = closure doesn=E2=80=99t need to be aware. As a precedent, it is perfectly legal to call a static class method on = an instance of that class: https://3v4l.org/5QKsN = =20 =E2=80=94Claude --Apple-Mail=_0BE5AA7E-A3FF-4DE3-8F3A-D36BE46907BB--