Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114616 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78333 invoked from network); 26 May 2021 11:42:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 May 2021 11:42:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4118C1804B0 for ; Wed, 26 May 2021 04:54:17 -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=-2.1 required=5.0 tests=BAYES_00,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-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (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 ; Wed, 26 May 2021 04:54:16 -0700 (PDT) Received: by mail-ua1-f48.google.com with SMTP id b1so607143uap.3 for ; Wed, 26 May 2021 04:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=C/zFs231u0GaQ1k6kF5fYykZRl5cz4ksXH+4kWAdwNM=; b=HF6vmOXB+iXKK2baekmKpJCesKjkKl54PXrYFT1z+UBVFG+jEdg0uWBaX7JwNqr5jR DiKsIa2koEIB4Xh62Ff2oq5YZPuUXkPDgZzbHlt9XxuH+OAHntsRhP2xq0y/azlWH9fz fCH0LHNy08eLuI0CltQaXb9VFo8c8jgswB4mVppY9PFAM1xc9E2c5Yu8yruWFdKv58V6 fl/oKC6woy5e0urbsxyTB3NsVimKunKZespTlTGVPMZOV2p0qUf2WfQccvd2zsD3Epos GOnvx/zO5X/5eNI/KE4ZlGlgZUzzu1grXSe4P1o2k35NA6xDJ7h6nnJGCAPmvwIVW4+0 zG2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=C/zFs231u0GaQ1k6kF5fYykZRl5cz4ksXH+4kWAdwNM=; b=gR6OBYI7otH3p6ns0/27rRDe+nmN89t2dOOpJUDguxuR8yjkthYHAtDA2yAqYFrCf9 qLoqrUCFDKOU6F4VA9xscRys/hb6mAMWfClPSsT+WmvvBXNjibA/j1r4mMnuXihAd4qj zIuVnglP3U/EsVp2athtPPhbFKwSuuNN51cWoBjDAgOWc4Az2ETwQsdHuEqRyOGKpR6A TnSmEA+AEz6rXwg2Ch+kCdpEkm/YCOfl8ecCceG+gQkIrChzVY9AjZQSIwoNli5RK0Dr saBMwEB9Miyc46GX/45TV1SmwsB5VPvt6i6b8ldwf3+6BUPBKO9ssSUDYlk0hrQCYKGR 7t4Q== X-Gm-Message-State: AOAM5317rjNyPtOc0KauZ+1wm8G2f9bt0T4miWt0ON+Sc6KmJa0WyQxe JBNlY1C9OOIuz+Tah3323n2DNYPG4AAEzisgt6M= X-Google-Smtp-Source: ABdhPJzB2CsYqClaVRf9mUnnoukA07rRrA1I3md6xz+U2qCUPVYdQ5RI1eqB/p9oVJNNx/Vg5cdFpTV06XYYg6N7CpQ= X-Received: by 2002:ab0:f5:: with SMTP id 108mr32886385uaj.106.1622030056004; Wed, 26 May 2021 04:54:16 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ab0:2613:0:0:0:0:0 with HTTP; Wed, 26 May 2021 04:54:15 -0700 (PDT) In-Reply-To: References: Date: Wed, 26 May 2021 16:54:15 +0500 Message-ID: To: Mike Schinkel Cc: =?UTF-8?Q?Iv=C3=A1n_Arias?= , "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] A little syntactic sugar on array_* function calls? From: office.hamzaahmad@gmail.com (Hamza Ahmad) > should array object be passed by value or by reference? > If we are to have array object, will it be exceptional? By value. Because array is a data type, we are talking about making it behave like object. In JavaScript, Arrays, Strings, and Numbers are objects; they have their respective properties and methods. Still, when they are passed to a function or a method call, they are passed by value, not by reference. We should pass arrays by value because it will let a function or a method modify it without changing the original array. If we make it a regular object, it will be a bc break. So, whenever a callable modifies an array, it will modify a variable out of its scope. I am talking about attaching some methods and properties to array (or largely, the string, int and float) type. In your manner, an exceptional array object that is passed by value, Which will have "key_first", "key_last", "keys", "values", "length", "type" (if PHP later introduces typed arrays), and "is_list" as properties, and "reverse", "flip", "map", "filter", "walk" and so on as methods. Such methods will be performed on a value, not a variable. In other words: `[1,2,3,4,5,6,7,8,9,0]->print();` will work. This way, it does not matter whether one modifies a variable or a value. According to the implementation of Nikita's extension, there will be functions attached to each method of a type. To remove this limitation, what if array is an internal array object? To make my previous statement regarding making array_* functions as method aliases for array->* methods, I give the example of mysqli. It has both ways of interaction, object-oriented and procedural. So, why not this with arrays? Regards On 5/26/21, Mike Schinkel wrote: > > >> On May 25, 2021, at 6:28 PM, Iv=C3=A1n Arias wro= te: >> >> Hi all, >> >> It sounds like scalar objects by Nikita: >> https://github.com/nikic/scalar_objects > > Yes, but Nikita wrote this note about technical limitations at the bottom= of > the repo README: > > Due to technical limitations, it is not possible to create mutable APIs f= or > primitive types. Modifying $self within the methods is not possible (or > rather, will have no effect, as you'd just be changing a copy). > > Does that mean that the scope of Nikita's proof-of-concept could not modi= fy > $self, or that it is simply not possible to modify $self given limitation= s > inherent in PHP? > > Further, does that only apply to scalars, or might possible arrays could = be > different? > > -Mike