Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115117 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80606 invoked from network); 24 Jun 2021 11:55:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jun 2021 11:55:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 76D331804D8 for ; Thu, 24 Jun 2021 05:13:46 -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.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 05:13:45 -0700 (PDT) Received: by mail-lf1-f54.google.com with SMTP id a11so9841025lfg.11 for ; Thu, 24 Jun 2021 05:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=dRBDjRagv5dgPjKVQ1MgicmNqrK/ppmxxndeMZqeslg=; b=nsgKV9zK4Y5F0b5ECZaac1aOWmPIjiBGrN0LDA6Aiq6nn9B1KdKw3v5i+chHaC9HZ+ icdPcEq8TjdAv4zCctztglT+jmZvF569Z7t6BQcg5iWLRelU8D96LqZC126OtiVaE4+B JR5vMfd2QCRq4QatKb/EZCzZXoPJpusKOSI5c3PX5VzBsrC5/BArr12gAeKdyvaimDG0 Rdx2bVOSQp5lHwvQzfSUT8EERrm8qYUGpoVL3m5cH9XoTlgYsPtypnsmRFL/MuSdgLM6 ZGe3/wtDc53LIw5z73XuBmAbWzjLMkvA8VF1CE7iBBYKn/XEZA9GhvI0UYlIZFbCEtgI lGJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=dRBDjRagv5dgPjKVQ1MgicmNqrK/ppmxxndeMZqeslg=; b=qaNRg1rHk5E7kW30mdpA+AWLcmSH3XBi7O+dMps3JCAdMeNuWpyCoYNYGgDThKCZh3 WoExLd0L9l/QtdyYhiCSgOO7mDcSsK2R5dFFVjlET8XH4ZUopmwwFGEcIWHS5kUbcw1r PcC9nws/KuUNtFdjN6K7CxsnLBGQ11l1mIsyAx/L3+FznXardlf4MuNZIR+lQfGbVuLF vBziaETGd7GNCAO1/Cai5uaWNvK8jzR5PyNZcg1MV5hD/YO/IOQIOXjrST7xUtmECuNr Y8s7a4pF/7dF+fDl/7KzE+jM20/o4gNqoUqXHFhh3074+cNZNKxNRRdPebAfr0QXyL2r Poqw== X-Gm-Message-State: AOAM5337sfzoVDXcZU1STrZaT452/S79JuF/kF14UHNy+rZjW+dzxCHd HFKNyja5m+eg3hhGlEjZw/jBkVtcrmp7H/WlM7PaNngouTk= X-Google-Smtp-Source: ABdhPJxELp5LEgkAo0VRg2tDQ63+1y66rE541+otj8n4hB3rZBoRXkKLAd7lgZp+XE8+xUlJ2D5Wfb/+ECNeXqOn8cQ= X-Received: by 2002:ac2:4ed9:: with SMTP id p25mr3550482lfr.576.1624536822086; Thu, 24 Jun 2021 05:13:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 24 Jun 2021 15:13:31 +0300 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Subject: Re: Checking that Closure is static From: elisdnru@gmail.com (Dmitry Eliseev) 18 june 2021 at 17:35, Dmitry Eliseev : > > 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 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. I sent Pull Request https://github.com/php/php-src/pull/7193 with a simple implementation. P.S. Sorry for PR without RFC, but I have not got any reply to my proposal yet.