Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114955 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4771 invoked from network); 18 Jun 2021 14:18:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jun 2021 14:18:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A09FD1804CC for ; Fri, 18 Jun 2021 07:36:00 -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_50,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-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 ; Fri, 18 Jun 2021 07:36:00 -0700 (PDT) Received: by mail-lf1-f49.google.com with SMTP id x24so17023971lfr.10 for ; Fri, 18 Jun 2021 07:36:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=tc9WdtLygi75tesh+flc0E+jChi47wDkdHmNFqgpc/k=; b=uOyOjE+B/9bmiOaze7twWv5byJ32QgZyyQrXFD7PKZkf561zk3qZ0Yg+Lzyb1DOowi 7B+jB570D9K5Z7gd3ZztGs6b5Zw49FjjdSQMCGALoQ/7SKpr3eMDJ6BxaDt5aV7vqFd7 ZpjrAiMxTD/+ewhIPoG26bOuILIUEyZqAH74GMl8dP2IfVlA5LwNKpTlQSvAWr5pbJ8g Jiv9d5SsYF0TkwSuXjT5BmIc4yWMoEDNJ0ZU36HfmI0/Gj2V42fZBc6L+pnMAbGeHBIC EfKxKHMe78qIreHPTGkMQTvnDxC9yPHBwqut0yJVJ0DUDNA0qZZeuRJuTx0lz8fneAlN 1DpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=tc9WdtLygi75tesh+flc0E+jChi47wDkdHmNFqgpc/k=; b=N1RSSwkAGcgWHVFyuuZsxqNKKdo3hI/Gr17Kcc0iBrFs18wi0aG0NJO4lLZkE9PAiW j0kv8Ppx4WFOpOe8Bxy/XYoaFmdpQKksV3eoW4IWPpse35uAkrpWRgjzjzu3xnTwK48e i1sEoHteW5/B/r8qRNJmODBFoY3da2zFYfFaDMu5qjXSkA3MH0CS5nN4L+EyRvoFMpLC MWLg7MyniAOvxXjCc88NPeJGdi13+KOjf4g21Bw2LjPDpQXW0OLUY+qhDtQFcZ/9N91Z +wcZs2y7HwRJLlW9xKBRQ4RlzYCaA480aE4gJN0psH5u5jjAzd+gMVlnBP6xiYmIZsSH Gfhg== X-Gm-Message-State: AOAM533Rh/7m+a2XC2o3YKvVCNRAvovWrrVvXzsApvZV8RvGm5GKKWxO JzZHvXt6Ip70iOuEPlgEYOarHI0rc8zoVRyf639Di3B4CUc= X-Google-Smtp-Source: ABdhPJy8jkDfFZ3sM1XVOnGkaJqUT+GnoBl4gfRm0qSSyb5kIWoAl3Yy+UyxX06MWh+6ChSRca7RLnsY1W715QyIhzI= X-Received: by 2002:a19:e00c:: with SMTP id x12mr3283557lfg.376.1624026958715; Fri, 18 Jun 2021 07:35:58 -0700 (PDT) MIME-Version: 1.0 Date: Fri, 18 Jun 2021 17:35:48 +0300 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000fadcd605c50b3d01" Subject: Checking that Closure is static From: elisdnru@gmail.com (=?UTF-8?B?0JTQvNC40YLRgNC40Lkg0JXQu9C40YHQtdC10LI=?=) --000000000000fadcd605c50b3d01 Content-Type: text/plain; charset="UTF-8" Hello! When I use a static anonymous function as an HTTP-action in some frameworks like: $app = new App(); $app->get('/', static function () { return new Response('Hello!); }) I get a warning "Cannot bind an instance to a static closure" in every $closure->bind($container) call inside of the framework. 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. So I propose to add a method like Closure::isStatic (or Closure::canBeBound, etc.) for ability of manual checking it before bind call: if (!$closure->isStatic()) { $closure->bind($object); } The method can contain simple statement: return func->common.fn_flags & ZEND_ACC_STATIC; It will be helpful if somebody needs to support dynamic and static callables both without warnings. -- Best, Dmitry --000000000000fadcd605c50b3d01--