Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107852 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33071 invoked from network); 24 Nov 2019 14:58:45 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 24 Nov 2019 14:58:45 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 43A662D19B6 for ; Sun, 24 Nov 2019 04:52:54 -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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,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-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) (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 ; Sun, 24 Nov 2019 04:52:50 -0800 (PST) Received: by mail-il1-x130.google.com with SMTP id u17so11640280ilq.5 for ; Sun, 24 Nov 2019 04:52:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eq499DFAO3qc2Xx+8pWbzpFP+wjfrsVnxyL+xmL0SPQ=; b=qMDXhNgwtr829CRd6qppOO4DpXakflJc21eq49atAFfyPpq3qEw5zHqgIc00vy4ieb v1h8AFvrgMN2//JqmJpmnP2ClSJwVbdrvuTNNKHfU3GyZ6WsXH9NXCGXewKxGb/eDKGh nmwaAX9Op7QtiHGv5Y5I6M9+Osf1/bkm1zLcEbkaWqmCiA/TM+Yw+YwN1Qc5FKuAtcSf mQ9HBh7RmOVVuA//2gaBDQls8o3l7ThhfE0Rf73LOK7CXHLamg0bGtdrdtpFZa6NVLtU ocxVb7p8/rwT52YrRb4jTM8dRlyx62kbWVmJx5ruAYYkvMxN8TEJ9pemdcbefgqDht9y Pn/g== 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=eq499DFAO3qc2Xx+8pWbzpFP+wjfrsVnxyL+xmL0SPQ=; b=VUYbaKAVdnjI/55u4bsNCbjgViJEaKTrjwVyb137uUoASR1GDH2YF7f5GSBXnQauH5 6VcWuOuS8Au4NvIWbwy9bInuYiJ+Rs2kJrBAVQb0eJJ84jjA4wXJkH/eFp2S3P/Ctgm+ f1GCyGZDmZ2YfSlBSXVLw825cNqdZ2GV5UyfkHRSXVS2V8HpXSlMo75qLdyn7iUYG/ev lj8kZbgxL5XKH3khabwYnwuEFJeKNVIRJpcHiE+9FqNiSOfc6YNLOVoPTpo0xEeC4/vZ Yp0y99qSyrlDXMhh2uQE2Jx9eoyo53i6noZxhYVSFHl+HttFZSyY+VCNAHSch/PR0VYt auwQ== X-Gm-Message-State: APjAAAX44JTE6M2TYgoE31nNDMDa7WGqr4FvIbO5DVbs1tZ0ceZJedCq kQp0svad7zaV1nUxRv6WO9tV0N4jBXWkru4OLDFk+Q== X-Google-Smtp-Source: APXvYqyuCzEdSfVKBRg14GJDft1KS2H8D3JsOykxZn83NYXaCSndAUPTdncqwHeLaBj5edaLaJf4IFWYU5XIYR9fud4= X-Received: by 2002:a92:5d08:: with SMTP id r8mr26756261ilb.283.1574599969924; Sun, 24 Nov 2019 04:52:49 -0800 (PST) MIME-Version: 1.0 References: <77a3eec4-275f-e2d9-1969-185abeab7f5d@aimeos.com> In-Reply-To: <77a3eec4-275f-e2d9-1969-185abeab7f5d@aimeos.com> Date: Sun, 24 Nov 2019 13:52:37 +0100 Message-ID: To: "Aimeos | Norbert Sendetzky" Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000deeea80598171f45" X-Envelope-From: Subject: Re: [PHP-DEV] Extend ArrayObject class From: ocramius@gmail.com (Marco Pivetta) --000000000000deeea80598171f45 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Nov 24, 2019, 13:16 Aimeos | Norbert Sendetzky wrote: > The ArrayObject class is only rarely used at the moment due to a lack > for almost all array_* functions beside the sort functions. > > Currently implemented by ArrayObject: > https://www.php.net/manual/en/class.arrayobject.php > > Missing methods that would be most useful: > array_=E2=80=8Bchunk > array_=E2=80=8Bcolumn > array_=E2=80=8Bdiff_=E2=80=8Bassoc > array_=E2=80=8Bdiff_=E2=80=8Bkey > array_=E2=80=8Bdiff_=E2=80=8Buassoc > array_=E2=80=8Bdiff_=E2=80=8Bukey > array_=E2=80=8Bdiff > array_=E2=80=8Bfilter > array_=E2=80=8Bflip > array_=E2=80=8Bintersect_=E2=80=8Bassoc > array_=E2=80=8Bintersect_=E2=80=8Bkey > array_=E2=80=8Bintersect_=E2=80=8Buassoc > array_=E2=80=8Bintersect_=E2=80=8Bukey > array_=E2=80=8Bintersect > array_=E2=80=8Bkey_=E2=80=8Bfirst > array_=E2=80=8Bkey_=E2=80=8Blast > array_=E2=80=8Bkeys > array_=E2=80=8Bmap > array_=E2=80=8Bmerge > array_=E2=80=8Bpop > array_=E2=80=8Bpush > array_=E2=80=8Brand > array_=E2=80=8Breduce > array_=E2=80=8Breplace_=E2=80=8Brecursive > array_=E2=80=8Breplace > array_=E2=80=8Breverse > array_=E2=80=8Bsearch > array_=E2=80=8Bshift > array_=E2=80=8Bslice > array_=E2=80=8Bsplice > array_=E2=80=8Bunique > array_=E2=80=8Bunshift > array_=E2=80=8Bvalues > shuffle > > > Furthermore, the already existing sort functions return VOID, which > isn't best for an object. Instead, returning the ArrayObject itself to > support a fluid interface would be much better, i.e.: > > $ao =3D new \ArrayObject([null, 'a' =3D> 2, 'b' =3D> 1]); > $ao->filter()->sort()->flip(); > > This change wouldn't break any existing code already using the ArrayObjec= t. > > > It should be possible to extend from ArrayObject too and have access to > the internal array. Therefore, a new method would be required: > > protected getArrayRef() : array > > The method is similar to the existing getArrayCopy() method but returns > a reference to the internal array instead of a copy. Thus, classes > extending ArrayObject will be able to implement additional methods > efficiently without the need to create copies of the internal array first= . > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.ph > Ouff, please don't extend `ArrayObject`: it is very quirky and keeps state in a way that is very much untransparent to userland: please use `ArrayAccess` instead. Even then, the various `array_` functions that mutate/map/filter would need to produce equivalent data structures by knowing the ctor of your array-alike object: better leave them alone, unless the output is a core `array` again --000000000000deeea80598171f45--