Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107851 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26872 invoked from network); 24 Nov 2019 14:22:35 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 24 Nov 2019 14:22:35 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 976502D1FB9 for ; Sun, 24 Nov 2019 04:16:43 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS34788 85.13.163.0/24 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from dd46610.kasserver.com (dd46610.kasserver.com [85.13.163.220]) (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:16:43 -0800 (PST) Received: from [192.168.178.20] (x4d0a6f33.dyn.telefonica.de [77.10.111.51]) by dd46610.kasserver.com (Postfix) with ESMTPSA id 6B7794340693 for ; Sun, 24 Nov 2019 13:16:41 +0100 (CET) To: internals@lists.php.net Organization: Aimeos GmbH Message-ID: <77a3eec4-275f-e2d9-1969-185abeab7f5d@aimeos.com> Date: Sun, 24 Nov 2019 13:16:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Envelope-From: Subject: Extend ArrayObject class From: norbert@aimeos.com (Aimeos | Norbert Sendetzky) 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_​chunk array_​column array_​diff_​assoc array_​diff_​key array_​diff_​uassoc array_​diff_​ukey array_​diff array_​filter array_​flip array_​intersect_​assoc array_​intersect_​key array_​intersect_​uassoc array_​intersect_​ukey array_​intersect array_​key_​first array_​key_​last array_​keys array_​map array_​merge array_​pop array_​push array_​rand array_​reduce array_​replace_​recursive array_​replace array_​reverse array_​search array_​shift array_​slice array_​splice array_​unique array_​unshift array_​values 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 = new \ArrayObject([null, 'a' => 2, 'b' => 1]); $ao->filter()->sort()->flip(); This change wouldn't break any existing code already using the ArrayObject. 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.