Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107823 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62586 invoked from network); 18 Nov 2019 20:30:25 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Nov 2019 20:30:25 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 05DA22D19B2 for ; Mon, 18 Nov 2019 10:23:07 -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,DKIM_SIGNED, DKIM_VALID,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-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) (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 ; Mon, 18 Nov 2019 10:23:06 -0800 (PST) Received: by mail-yb1-xb29.google.com with SMTP id k17so7595887ybp.1 for ; Mon, 18 Nov 2019 10:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:mime-version:subject:message-id:date:to; bh=evEaqvrDhBHsyLrbc/BuI9DOEeaFF3zfsU/X/a7e6OA=; b=c9mN8cB1T+oH9ZS1qcE0L4L5Muz9EVQGs7jkO7CscQ2ZvLu5iI15NtGOyaZEdWmIiW yeiLM9M7VfIRV0UnQGjkv98ZRNfe84dil3bXp9HsGNS4scpPfsByo20EJ6QnkymTM+Ro jrnOmV12UHAGWpPQvxdbt6Gwu8BGFZ7iO79fbaXIoufIEg5DeBAiYidALXcsB/mhcboO myGbg3QyJ8KjdAoR+M+dByB40ekeNVmFtfcd3p4tJdcEjmQ4LKFQM/Nkx1oxbMgqx0ep uF/ru/6rrM3tIoI0VxGagRSLkZLczg52BNevobOWCOumx03WZ8HLUDj7R7ch8c8GTeBh vRYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=evEaqvrDhBHsyLrbc/BuI9DOEeaFF3zfsU/X/a7e6OA=; b=KRTF1eS4h7ytfisrenGvjCCHZaVbJtP7wIQdTRbRulUTEIFd/qC6IQAHSkRpCxkTl6 7uNnpuF9VuTJl/8HW7jZ6nG5ZWiMs0LSYCT4zOcHlc6CZpSfN2XJ2VWIJth3hG2H36SZ k6EmqxciU3n+veNmdCMGuRp91zqaidTV5R4CiTfrshAZ2x40/0KS3x+iLojFvIqYOmDi cg+dKnWNiIvHUaroWRNLv/xoxoXSVj3CsMH+8WP1VDMj3If9nE1q8FSXD93qcYQXClx+ LOM0oKn17uPDIdNnxl2CIIH5V7ref3Li7HZSUS3PqncdqzSKQls9jMuSq99ekTypEebw Fwfg== X-Gm-Message-State: APjAAAVfKjz+mkfNtvO2AeMeY8fgkvdr7f4qiTbGJaEhXf1LbpCTsw3G W3V6EwDxTxvccJnqZsJUR6XAD0a2behrMQ== X-Google-Smtp-Source: APXvYqxcyApUA6IsZx4gcRGnrt1lqVVgJyKNn/z17LM4RuoeNzjRtE4MsE64/RvuyQQp7xVMNozsBQ== X-Received: by 2002:a25:b116:: with SMTP id g22mr2069480ybj.183.1574101384879; Mon, 18 Nov 2019 10:23:04 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:1131:c4e4:216c:a411? ([2601:c0:c680:5cc0:1131:c4e4:216c:a411]) by smtp.gmail.com with ESMTPSA id l34sm3204197ywh.40.2019.11.18.10.23.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Nov 2019 10:23:04 -0800 (PST) Content-Type: multipart/alternative; boundary="Apple-Mail=_9112A57D-CCA7-48A5-B41A-E117D2D0DADD" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Message-ID: <6A47C8D5-FDCA-45DA-9BC3-DC9417FEE36E@newclarity.net> Date: Mon, 18 Nov 2019 13:23:03 -0500 To: PHP internals , =?utf-8?Q?Micha=C5=82_Brzuchalski?= X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Enabling ArrayObject et.al. to fully replace array usage From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_9112A57D-CCA7-48A5-B41A-E117D2D0DADD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 I decided to create a new thread since I was diverging the topic. > On Nov 18, 2019, at 5:36 AM, Micha=C5=82 Brzuchalski = wrote: > Currently, arrays all together with rest of scalar types are = value-types > which means when they're passed on (unless passed by a reference) = their copies are modified but not the original one. > That's cause object's in PHP are reference types, when passed they're = always passed by reference.=20 > Thus making a general ArrayObject class even internally for now should = follow value-types semantics.=20 > How do you want to reconcile that? Excellent point. Would it not be possible to automatically do a clone on pass when = __asArray()=3D=3D=3Dtrue, such as this:=20 bar =3D $newbar; } class Foo extends ArrayObject { public $bar; private $as_array =3D true; function __asArray(){ return $this->as_array; =20 } function setAsArray($as_array){ $this->as_array =3D $as_array; } } // PHP 7.x $foo =3D new Foo(); $foo->bar =3D 'baz'; setBar(clone $foo,'bazoom'); echo $foo->bar; // outputs: baz setBar($foo,'bazoom'); echo $foo->bar; // outputs: bazoom // PHP 8.x (maybe?) $foo =3D new Foo(); $foo->bar =3D 'baz'; setBar($foo,'bazoom'); echo $foo->bar; // outputs: baz $foo->setAsArray(false); setBar($foo,'bazoom'); echo $foo->bar; // outputs: bazoom > Another thing is when shaping an OO API on general array class -> = ArrayObject all of the existing array_xxx > functions IMO should be deprecated and that's not likely gonna happen. Are you saying that ideally we'd have $array->map($callable) instead of = array_map($callable,$array)? Totally agree, but I'd rather have array_map() work with ArrayObject = than wait for a "perfect" API that may never come. > If you ask me why I think like that, well if ArrayObject is going to = be automatically served from all arrays > keeping array_xxx functions makes no longer a sense, the only thing = they could do from that point > is only calling an ArrayObject method, which is different from what = they do now they return a new value-type > a new array with filtered, mapped key-value array elements, when = working with objects you expect=20 > them to mutate themself if they're mutable or return a brand new = instance when they're immutable. I think it definitely makes sense, because backward compatibility. We could easily layer a better API on later, assuming opt-in via = interface so that no BC would occur. > maybe there is an additional initialization needed besides of = key-value pairs only, for eg. additional constructor argument. ... If = that happens for internal array_xxx functions it would be hard to guess = how to create a new instance, > they'd become a thin wrapper of calling ArrayObject like methods, = nothing more. In the case of userland code extending ArrayObject or its related = interfaces could it not simply leverage __clone() if it needs to create = a new instance of self to address that concern? -Mike= --Apple-Mail=_9112A57D-CCA7-48A5-B41A-E117D2D0DADD--