Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114654 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55548 invoked from network); 28 May 2021 00:59:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 May 2021 00:59:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA7401804CC for ; Thu, 27 May 2021 18:11:13 -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.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HTML_FONT_FACE_BAD,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-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (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, 27 May 2021 18:11:13 -0700 (PDT) Received: by mail-qt1-f172.google.com with SMTP id g8so1657661qtp.4 for ; Thu, 27 May 2021 18:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=iLDjzWXdQFJ8CnB2m8mNar3vVn+sPJrP88qQ1vW3flw=; b=kPPc0pwTJLPSNjwW5YtMEpyuHFiFGl1hrIYu9qDBQfjEyi3+MoXWsDKqr97slLvMH5 4HfcO1wwBcPZZ39E8AMvtxINIaVJXh3B/gRnrI5aLOCsJOR2jKFhXd8lL7n/FKtPMO5Y WU1gNE6YbsGWZW4B5/mM1Pk1BZVdRBMSL4M19ALkr2gorOMzP/VlBv6pInzd1ubYzVMa 47HAMLamp6CB8PYhC5yKBAO15XLpSW/HpecsEWp7wi8hU2mTj4OXx+JFdhAvoPuWr0Ub 1yNlzr6DlzrA6pYxU10jB+zHx8LGGIL8SzoA/RLhthcfRm/Et1SUVEwgZWWX1X186Q7p Kg/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=iLDjzWXdQFJ8CnB2m8mNar3vVn+sPJrP88qQ1vW3flw=; b=oCDjvIbjjsE6XNKBuFzr6uYYXTb1dxv4kXSPoyy2F6COeKP0dyItbxi4X5vXUuNDj4 iv8r4BQMJCMYHFnGeWKKKjm+ZIjMHBHm+7uTph4aOjKAwnZabPKsiWTEZ0vdln5ALupL dQysEWLC9mJSwCkyow7xd97zq79QSGOxPnHBSBUmV6Z1coTF5cXIXCsLZGlLxt2NhuXr 5K86MbiSCsaiy53ihTQc7Fb278tNALzI+e05kqceSTwu/DzdaKafBuljcM0WDdCO7FoL Z8TMD6pZGAXhny6PrNGYNFXbJINbjimAwnWPaiWChyjNPTf97lziJzq40JUpcPv8EJgl EPmw== X-Gm-Message-State: AOAM533aMsS+PzXeCXHQ0PH1uaEiter3ZiqS715gxycdJZpZIqr1p+gN fE2+uRw+br5mhP5wSN66E5ue9g== X-Google-Smtp-Source: ABdhPJw1pWmDOk5cz+XqGzidochIz1RpeDkUHUNixr3lAgNeSsqKPXY/jOn8JEG/DCYV46hG1/O0lQ== X-Received: by 2002:ac8:574d:: with SMTP id 13mr1328384qtx.380.1622164270737; Thu, 27 May 2021 18:11:10 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id g3sm2422281qth.19.2021.05.27.18.11.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 May 2021 18:11:09 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_ECEB1DD7-672D-4E71-8436-F56F6AA5D429" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.6\)) Date: Thu, 27 May 2021 21:11:07 -0400 In-Reply-To: Cc: "internals@lists.php.net" To: Hendra Gunawan References: X-Mailer: Apple Mail (2.3608.120.23.2.6) Subject: Re: [PHP-DEV] A little syntactic sugar on array_* function calls? From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_ECEB1DD7-672D-4E71-8436-F56F6AA5D429 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On May 26, 2021, at 7:44 PM, Hendra Gunawan = wrote: >=20 > Hello. >=20 >>=20 >> Yes, but Nikita wrote this note about technical limitations at the = bottom of the repo README: >>=20 >> Due to technical limitations, it is not possible to create mutable = APIs for >> primitive types. Modifying $self within the methods is not possible = (or >> rather, will have no effect, as you'd just be changing a copy). >>=20 >=20 > If it is solved, this is a great accomplishment for PHP. But I think > scalar object is not going anywhere in the near future. If you are not > convinced, please take a look > = https://github.com/nikic/scalar_objects/issues/20#issuecomment-569520181. Nikita's comment actually causes me more questions, not fewer. Nikita says "We need to know that $a[$b][$c is an array in order to = determine that the call should be performed by-reference. However, we = already need to convert $a, $a[$b] and $a[$b][$c] into references before = we know about that." =20 How then are we able to do the following?: $a[$b][$c][] =3D 1; How also can we do this: byref($a[$b][$c]); function byref(&$x) { $x[]=3D 2; } See https://3v4l.org/aPvTD I assume that in both my examples $a[$b][$c] would be considered an = "lvalue"[1] and can be a target of assignment triggered by either the = assignment operator or calling the function and passing to a by-ref = parameter. =20 [1] = https://en.wikipedia.org/wiki/Value_(computer_science)#Assignment:_l-value= s_and_r-values So is there a reason that -> on an array could not trigger the same? Is = Nikita saying that the performance of those calls performed by-reference = would not matter because they are always being assigned, at least in the = former case, but to do so with array expressions would be problematic? = (Ignoring there is no code in the wild that currently uses the -> = operator, or does that matter?) I ask honestly to understand, and not as a rhetorical question. Additionally, if the case of updating an array variable is not a problem = but updating an array expression is a problem then why not just limit = the -> operator to only work on expressions for immutable methods and = require variables for mutable methods? I would think should be easy = enough to throw an error for those specific "methods" that would be = mutable, such as shift() and unshift() if $a[$b][$c]->shift('foo') were = called? Or maybe just completely limit using the -> operator on array variables. = Don't work on any array expressions for consistency. There is already = precedence in PHP for operators that work on variables and not on = expressions: ++, --, and &. IF we can get a thumbs up from Nikita that one of these would actually = be possible then I think the next step should be to write up a list of = proposed array methods that would be implemented to support the -> = operator with arrays and put them in an RFC, and to flesh out any edge = cases. -Mike --Apple-Mail=_ECEB1DD7-672D-4E71-8436-F56F6AA5D429--