Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111200 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60886 invoked from network); 27 Jul 2020 13:26:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 27 Jul 2020 13:26:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D4E7180509 for ; Mon, 27 Jul 2020 05:22:25 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-oi1-f196.google.com (mail-oi1-f196.google.com [209.85.167.196]) (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 ; Mon, 27 Jul 2020 05:22:25 -0700 (PDT) Received: by mail-oi1-f196.google.com with SMTP id t4so14131121oij.9 for ; Mon, 27 Jul 2020 05:22:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UxXuYyCiATXlEzR2yvhuhuGbC1+JyqwINLNQ+DZNtbc=; b=KsmSyc4wt88ppItuyS/MqulSoBebD0TGveuTdubwR/mnwtkne2p0SkICXFI9fE862e F/OG9ow7nDjP5u9Dlf7Cyd4SkOKQiY/hwc6AZeIfCopY9ixEZHLZbNLXGs0Sxhy2oBEe N6aKa5ONMytVmioS2jiH5QldXFbown8T2V9xLQUPBzX+IUSbVvR+vcIq0ZayuHd9hW8w pI2R6lzosL01iJgTupmAgu9pOuTN5TMiqMDL7XR06KmZvh3fz3LX6BILD3QAn1Xa35ua jKdd4GwJueD0KvA+pB59tEcw20rAXMGiuU0RSEp74IKYRa4z2x8pKUibcShdwSDYKgNj ZP7Q== 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=UxXuYyCiATXlEzR2yvhuhuGbC1+JyqwINLNQ+DZNtbc=; b=U4era6G/tNmLjzl9cX4IoQUYF46Qv+acOktoZnlpV2ssdrIDx16CHmFLOACMSeLQBk /5Y0uq0bS77JtC1x4JurkSElzUNPD4SwRHJHCeU2CtQbjsfhAaeKa+NcAAkOVF1ggJdu Thqzh0WUmjqZCROB11fISJHX0q0umFYEsF/Hj+XJdUIXUEL1Wr2Vl8/Lc1GEWEDjgy6b w1iOaWGpEcw0zQjzyNLMAoV0R1lOPUejCyrvq26F3BU0RNzh1Gvl6BZ3e9kTHgXQafxx EXgpQWkfgG+xI0znH0vX6no5wP1OpIrtjFLirFc4XTiBeRRhzk7KeoykYcGasBhJOh93 baOQ== X-Gm-Message-State: AOAM532cPhKGtn1+U8zklvnSjEClPgqUYacBmTo2hsMWFYUrgMXt7x87 FG+8VvV82vqwM41f3s1A18gEc2QjLbxfTdgLSaHdiA== X-Google-Smtp-Source: ABdhPJwUTirn3psbKmotkKw/T2tZWtjwmv8iWsbZHSX8No1PTf+r6SQKKQRMYoDWprkEdTMbGEq+xl1/obbAK5z8SuE= X-Received: by 2002:aca:494d:: with SMTP id w74mr18305700oia.97.1595852542900; Mon, 27 Jul 2020 05:22:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 27 Jul 2020 14:22:11 +0200 Message-ID: To: tyson andre Cc: Sara Golemon , Nikita Popov , Bob Weinand , Benjamin Eberlei , Chris Riley , PHP internals Content-Type: multipart/alternative; boundary="000000000000ef0fe505ab6b5fc2" Subject: Re: [PHP-DEV] [RFC][Proposal] Renamed parameters From: andreas@dqxtech.net (Andreas Hennings) --000000000000ef0fe505ab6b5fc2 Content-Type: text/plain; charset="UTF-8" On Mon, 27 Jul 2020 at 03:18, tyson andre wrote: > Hi Andreas Hennings, > > > 1. Calls with named arguments can only happen on: > > - explicitly named functions (e.g. no call_user_func()). > > - constructor calls with an explicitly named class. > > - object methods, if the object variable is type-hinted or a type is > known at compile time. > > This proposal would seem to depend on moving opcache into core, among > other things. > Depending on how it's implemented, the condition of "a type is known at > compile time" may also depend on whatever opcache optimization passes were > enabled, > which would make the behavior of whether this throws an Error at runtime > unintuitive to users. > Obviously there would need to be a consistent definition about how the type of a variable should be determined. And there would need to be a way to determine this at runtime, in case that opcache is not enabled. This could be the same system that is responsible for runtime type checks. Perhaps we should drop the "is known at compile time" and only support explicit type hints. Anything we do here should be dumb static analysis, not smart static analysis. E.g. function foo(I $obj) { $obj->setColor(color: 'blue'); // Good, based on I::setColor(). $obj2 = $obj; $obj2->setColor(color: 'blue'); // Error, because simple static analysis cannot determine the type of $obj2. } > (e.g. `$a = SOME_OPTIMIZABLE_CONDITION ? new A() : new B(); > $a->someMethod(namedArg: value);`) > Any "optimizable condition" would have to be treated like a regular variable with unknown value. So in the above case, named arguments would not be allowed. > > - `SOME_OPTIMIZABLE_CONDITION` may depend on the php version or > environment (e.g. `PHP_OS_FAMILY == 'Windows'`) > > A recent secondary poll on a rejected RFC I proposed did indicate broad > interest in moving opcache to php's core, > but I doubt that'd be done in 8.0 due to the feature freeze, and I also > doubt optimizations would always be enabled because of the overhead of > optimization for small short-lived scripts > ( https://wiki.php.net/rfc/opcache.no_cache#if_you_voted_no_why ) > > Also, the times when a type is known (with 100% certainty) at compile time > are known by opcache but unintuitive to users, > due to the highly dynamic nature of PHP > (`$$var = 'value'`, references, calls to require()/extract() modifying the > scope, globals being effectively modifiable at any time, etc.) > Even for typed properties, the existence of magic methods such as > `__get()` (e.g. in subclasses) means that the type of $this->prop at > runtime is uncertain. > - `__get()` is called if it exists when a declared fetched property (typed > or otherwise) was unset. > Good point. One thing to note, it seems __get() is only called when the property is accessed from _outside_. https://3v4l.org/sY96q (just a snapshot, play around with this as you feel) I personally don't really care that much about public properties, I could happily live in a world where named parameters are not available for objects in public properties. Or alternatively, we could say that it is the responsibility of the __get() method to return an object that is compatible with the type hint on the public property, IF named parameters are used. Even if all of this does not work, I think the idea still has merit: Evaluate the parameter names based on a known interface, instead of an unknown implementation which may come from a 3rd party. Perhaps a type hint is not the best way to determine this interface.. Greetings Andreas > > Regards, > - Tyson --000000000000ef0fe505ab6b5fc2--