Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126465 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 qa.php.net (Postfix) with ESMTPS id 48BE61A00C1 for ; Thu, 20 Feb 2025 15:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1740066104; bh=ajA8CBbCN1Nv8N58v6RQjL9LQtq+s0V1G33xpCc667o=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=YQMaG71byQAzSGjtgkw+fp+rLD56ZwKcjyGLXOufMHCQ55CRysIYU5GjFJWEkx2iC TlYZfio/qYsRFxQZPSn0F3kdjY1mZPEzg7JLRBNVe0h/79D+vhgqbt+qqG6uotVhAh a82D18iCqGo+YFuRUQ7o5PR+Zdocm71eS6T4GJCjtPiFi/gM6QbGwtuC0Qmi5Wmc/G pzf1iETznc3Rn56OqQgoovFoye/cZOGIHCThftxhKtwvWftwcKPhxwJBo1eqw0RKnr fJoCIFK8l6JgQu0/SoprU4BJdUU9rqOIdaGmxYFczGRVb6NGPBM0iBBRw6H76s+Z4p 2aHIxi1LPcHCA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F1F9D1801E6 for ; Thu, 20 Feb 2025 15:41:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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, 20 Feb 2025 15:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1740066259; bh=PNbOIQAJy++bsGdPCVn9P4NUYM5DJKjKbVpLJF8BLbg=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=eJDSQFKmtdJUqYKXAKrue8jaAvd0v/6fhQ+3r3m/RnhRlaOGM3qPmNtuArrzMvGuI s3igmdYA/fHyodCoy+UV2863R06yoGVEdyat4C2Em9Z/jjOjVWQy3ri2pG40EjCgPa FRAFOcbm7t/k3k0XzIOQAZ1fcZB5/FX+UpJBjODWPlNL6D8my0dUBozsJnLnBx29J9 ATPetNnGeOvLlfTUDo8ymyTx66snaFM2kpRGSPGbnjftUu24D+47e7niz1Ql6TtyEw fENy6xqMNVkxxNnx7yIqso10/GstqgGVNlMBlVBRBW5peyAYF+olMFrWYwpYXMiFe2 xveqwIk4v9bBw== Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 20 Feb 2025 16:44:19 +0100 To: Jakob Givoni Cc: volker@tideways-gmbh.com, internals@lists.php.net Subject: Re: [PHP-DEV] Re: RFC: Marking return values as important (#[\NoDiscard]) In-Reply-To: References: <5c142df3-94f8-45ba-b5c6-af3b4f7caa8b@varteg.nz> Message-ID: <1e29b3153978bbb01357e2c41a375be3@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-02-14 10:10, schrieb Jakob Givoni: > I think all the native attributes so far, with the exception of > #[\AllowDynamicProperties], > only affect the program at compile-time, or by emitting errors. > They don't affect the program otherwise by changing behavior, > throwing exceptions etc. (As long as you don't use reflection, nor > promote > errors to exceptions.) > > AllowDynamicProperties is the only one that may change the program > behavior > at run-time by throwing an exception if the property is removed from a > class while running PHP versions 9.0+. This is false. The `#[\SensitiveParameter]` attribute changes the behavior of argument capturing whenever PHP creates a backtrace. This includes the backtrace added to Exception objects, the `debug_backtrace()` function and the fatal error backtraces added in PHP 8.5 with https://wiki.php.net/rfc/error_backtraces_v2. This is also listed in the backwards compatible changes section of the `#[\SensitiveParameter]` RFC: https://wiki.php.net/rfc/redact_parameters_in_back_traces#backward_incompatible_changes > 2. Custom exception handlers might see objects of class > \SensitiveParameterValue, despite the parameter having a different type > within the method's signature. You mentioned “by emitting errors”, but I don't think that this is applicable here, since `#[\SensitiveParameter]` does not emit an error by itself and because it also affects the `debug_backtrace()` function, which is sometimes used for meta-programming. - > I don't mean to be rude and use your own words against you, but I found > this quote in the "Why an attribute and not a keyword?" section of > your #[\Override] RFC: > >> This RFC proposes an attribute instead of a keyword, because contrary >> to >> other modifiers (e.g. visibility) that are part of the method >> signature, >> the attribute does not affect behavior or compatibility for users that >> further extend a given class and neither does it affect users that >> call the >> method. It is purely an assistance to the author of a given class. > > (and I apologize if I misunderstand your intention or take it out of > context completely), but > I like the sentiment that "the attribute does not affect behavior or > compatibility for users" > and that it's part of the argument for an attribute instead of a > keyword > (language construct). > > I feel like #[NoDiscard] is getting dangerously close to being part of > a > method signature, > especially if it throws exceptions at run-time (which I know it doesn't > do > in your RFC, so I'm less against it). The situation with `#[\NoDiscard]` is indeed different to `#[\Override]`, because it affects the *user* of the API rather than the *creator* of it. But as you said, it doesn't throw an Exception by itself, but emits a warning which like other warnings only affects behavior if you specifically decide to do so via a custom error handler. And even if it would throw an Exception, having the Attribute would be “more visible” than an Exception that the function itself throws, since PHP does not implement “checked Exceptions” as in Java and unless the author adds a `/** @throws SomeException */` PHPDoc it's not clear what Exceptions might be thrown (or if any Exceptions are thrown at all). Given that other languages also implement it as Attribute + Warning, I'd say we're in good company here. In case of C, using the `-Werror' flag for your compiler would then be equivalent to a throwing error handler :-) Best regards Tim Düsterhus