Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107813 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 17127 invoked from network); 18 Nov 2019 01:36:07 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Nov 2019 01:36:07 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 5726F2CF9C9 for ; Sun, 17 Nov 2019 15:28:38 -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-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) (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, 17 Nov 2019 15:28:36 -0800 (PST) Received: by mail-yb1-xb33.google.com with SMTP id q18so6445632ybq.6 for ; Sun, 17 Nov 2019 15:28:36 -0800 (PST) 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=xsjMTV1eJyhJqLROMUeDNmLF2cGoDZlqGyCARKBmdvQ=; b=P3fe9tzq47Icfl9A7MDd1/nSTs0b66hcHJpQgAzV2sfNwctRAkMIwrkPCgJ2ZWIbNB DL57qM2XGBK20TtrJ4gNTwixcV0KgI890XM7z4iH7m+L6+Ww7TqAiweHftOU6rTV39aN kS+zHPsxurBYRCuJcYbtOEYTRduzQaRPy1x+mjF0KWw0rZzcS08bzV8lX4mFHzxH+dnV q+MMA5AfyGM7GZkonkzpg8IcCWXa0nqs+atoLb3glNyiJbU78O3AuSpEe9J0rUiNEIwM 5sG0/pjG9Ld5W2mkhHrRMmDxNFaoziCJx9o5JX6TK+HZ1mNOEsnVjCPsM+CvbeXGl/Vw 6RIw== 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=xsjMTV1eJyhJqLROMUeDNmLF2cGoDZlqGyCARKBmdvQ=; b=R+qHsE7Nr9QoNlSqDMQq+G5svOWUWmPrgzwf09IrhwxpNdwl1+/ayyCYL7Fcfthldi 3TcWS82l7GSa+eeBVhIxdDJ2f2oXy/Oj28bpa9uQ/dCvvX9rc3+iyulhqe/LKiqSqE1J zKtc+LA3cupWDdJ7jOJ55mJRA8wsE1dnFUD62FGI8WGRE4XH9t/DrX25FJaEp98h3XXN WOkFNAcNQZzs1T/ub9wTVRayAJxCRSB313efMw1Bf4oADekIG7284X/9ubKtZybxayq1 KH2l9rg9PDF58PZ7Y8OesBrwRQfd6ligXS99L0tZVU8YJkqpV20xzzJAf+bs335VObxK SjXw== X-Gm-Message-State: APjAAAVyFk3uf/8Q+QQFN50E/ygbw7L7rUU+Q5LTnx4b4/CActzrzT16 TIMzqk+BGVxsov80YlzA0gkMgqaUmZbb+w== X-Google-Smtp-Source: APXvYqyWjg895g3rknq2Toh91GyLcFuwTM5rQSG83o4MPak6GzfOtFDRHLs5BGZXNsBa8mOm4iYweA== X-Received: by 2002:a25:d46:: with SMTP id 67mr21823285ybn.164.1574033315956; Sun, 17 Nov 2019 15:28:35 -0800 (PST) Received: from ?IPv6:2601:c0:c680:5cc0:3536:e373:d5ec:26a8? ([2601:c0:c680:5cc0:3536:e373:d5ec:26a8]) by smtp.gmail.com with ESMTPSA id j67sm6745261ywf.71.2019.11.17.15.28.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Nov 2019 15:28:34 -0800 (PST) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_53965E7D-AEFF-4910-AA60-04F2038F2E22" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Sun, 17 Nov 2019 18:28:34 -0500 In-Reply-To: <461958fe-182e-59bf-9fdb-b110fd09e2b2@aimeos.com> Cc: Aimeos | Norbert Sendetzky To: PHP internals References: <461958fe-182e-59bf-9fdb-b110fd09e2b2@aimeos.com> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] Concept: "arrayable" pseudo type and \Arrayable interface From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_53965E7D-AEFF-4910-AA60-04F2038F2E22 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Nov 17, 2019, at 9:41 AM, Aimeos | Norbert Sendetzky = wrote: >=20 > Since PHP 7.1 there's the "iterable" pseudo type hint that matches > "array" and "Traversable". >=20 > PHP frameworks would profit from support of an "arrayable" pseudo type > hint that matches "array" and all objects that implements = "Traversable", > "ArrayAccess" and "Countable". If we are going to open up arrays for enhancement in PHP 8 I would ask = that we seriously consider addressing the various differences between a = built-in array and an instance of ArrayObject and/or the related = associated interfaces such that the objects can be used interchangeably = with a built-in array, i.e. that ArrayObject and the related associated = interfaces can fully replace the use of arrays when refactoring. Specifically I would propose that we provide some type of mechanism that = would allow the developer to cause is_array() to return true on an = ArrayObject/interfaces. Maybe something like this (I have not = considered all the special cases, I am just spitballing in concept = here): class MyArray extends ArrayObject { function __AsArray() { return true; } function hello() { echo 'Hi!'; } } =20 echo is_array(new MyArray()) // outputs: true ? 'true'=20 : 'false'; =20 Also, when the object is used by any of the internal PHP functions that = expect an array, such as sort() the internal function would treat the = object as an array inside the function. This also means returning the = object from methods like array_filter() when an ArrayObject with = __AsArray()=3D=3D=3Dtrue is passed. Even though these objects would be treated as arrays when in an array = context they should still be able to call their own methods, e.g. $array =3D new MyArray() $array->hello() // outputs: Hi! ? 'true'=20 : 'false'; =20 This would go a long way to allowing PHP developers to incrementally = clean up the gobs of legacy code in the wild, and move to objects where = appropriate. -Mike= --Apple-Mail=_53965E7D-AEFF-4910-AA60-04F2038F2E22--