Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107885 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97432 invoked from network); 28 Nov 2019 19:18:41 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 28 Nov 2019 19:18:41 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 5807D2D1FE8 for ; Thu, 28 Nov 2019 09:13:53 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from mail-vs1-xe44.google.com (mail-vs1-xe44.google.com [IPv6:2607:f8b0:4864:20::e44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Thu, 28 Nov 2019 09:13:52 -0800 (PST) Received: by mail-vs1-xe44.google.com with SMTP id x21so17869504vsp.6 for ; Thu, 28 Nov 2019 09:13:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZzVk4hkP8Jgwer2M/cCMMcCYQvxGM+yT6AODA//3LKc=; b=RTEb9AR4Pr7dmi9xuQPrKHA57/ADS3VTFzcSej2MT6bw9eb0aDPwtY6LNDIo88+Jj8 7msBWuim9y9uXRUplUk0jOEzkaY+KoGWVUhW/Ae+TAImaJquGbUEq5QVOp5BDcHUwR6U SzW2pfjWp2btVvCiKP+fRjH83q1L9X07DsyzNwVSriauws1puSa2KwrkzFKjOcduw8vw v/Cz+s7p/E7HJMeiRcRxGWgapJi1QM4kZIB0YL+YXQFdIT6KIkLzOjoMl57Xjx3pHllS K4iEsxVZQQESB8dkN11hEFj50z3vs794Bi7AIIBlG/KUNO8AuAiP7bi/2g4qxtJqlEKy pGrw== 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:cc; bh=ZzVk4hkP8Jgwer2M/cCMMcCYQvxGM+yT6AODA//3LKc=; b=JCXIdFu69vKsniO0b7naYDwk4VwwMvM7puupvGdES93Wkmnmzw5jS1E6ZefIYVjM30 NwCvpMvmfc7MrXPTaaQiF1kaLlyzw+CNIwHcrchOfCcepY0FpBSj6fxsBS4fIPvIHMoV u9MtnIXl+7CWrzfiyJ11AnLhz1qdhLJoZxpd0gogA27GOkrrgZ6YQ9IT8lh2NUdu/3MT EoakWJYIFI42bjHe31PuIPEbzvuMjCKHlTz4lGo7APECrBef/IrGtvzwexEjiETGHHRg I2gjHbQ5mWVSOpzm5ONGSrht6gkL/ZXLry1BPjiwoGrzwBoym9MFT0U4gaZqfwt/NvRk 0T9g== X-Gm-Message-State: APjAAAXLBJx1pOH9oKXnpVztAs/RcG9CpgPkB7Wd71jKSnXNtv5ZYZr9 cgoFiLCF/dywIOaJZ0MG49QfSYObCK0vFOdFKSTRJw== X-Google-Smtp-Source: APXvYqz4MG3ceax5Yk/IrhfMuerDeDQx0c0Dve811obxmVY6vrHwfjM0W9FFfyfiehfJ7G+tzaK6ZrAFOagFnUDjjKo= X-Received: by 2002:a05:6102:226e:: with SMTP id v14mr30123553vsd.30.1574961231805; Thu, 28 Nov 2019 09:13:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 28 Nov 2019 17:13:40 +0000 Message-ID: To: David Rodrigues Cc: PHP Internals , Claude Pache Content-Type: text/plain; charset="UTF-8" X-Envelope-From: Subject: Re: [PHP-DEV] register_shutdown_function() not supports private methods From: Danack@basereality.com (Dan Ackroyd) On Wed, 27 Nov 2019 at 23:33, David Rodrigues wrote: > > Hi internals, > > I am using the register_shutdown_function() inside a class, and then I have > created a private method to be called during shutdown. I have noted that if > the method is public it works, but private does not. > > This shutdown function should be private, > to avoid execution at a public scope. That is one of the reasons Closure::fromCallable was added: https://www.php.net/manual/en/closure.fromcallable.php So like: register_shutdown_function(Closure::fromCallable([$this, 'leave' ])); Or in your example: https://3v4l.org/MSLA4 > spl_autoload_register([ self::class, 'privateMethod' ]); // OK That is not OK. It might not give an error, but it's a bug if a private method can be called accidentally, without jumping through the deliberate hoops to work around private methods. Claude Pache wrote: > Another workaround is to use a closure: Although that works, using Closure::fromCallable() has the benefits of preserving the parameters and their info. function foo(int $x) { } $fn = Closure::fromCallable('foo'); $reflection = new ReflectionFunction($fn); foreach ($reflection->getParameters() as $param) { echo "Param type is: " . $param->getType(); } // Output is "Param type is: int" cheers Dan Ack