Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86822 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92810 invoked from network); 23 Jun 2015 23:02:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jun 2015 23:02:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.160.175 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.160.175 mail-yk0-f175.google.com Received: from [209.85.160.175] ([209.85.160.175:33249] helo=mail-yk0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/04-04861-A75E9855 for ; Tue, 23 Jun 2015 19:02:19 -0400 Received: by ykdt186 with SMTP id t186so14459625ykd.0 for ; Tue, 23 Jun 2015 16:02:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ZfNRv8PQA8jAbKyWfTn34AOQHVno9WdlSWNqRSMNSB8=; b=VdgQgatGBsZs8eCOw0TPkzmLZEUQt6+X940d13Jh2RVZeofyU7ksr6tE9XuZolrCgq 4niz95+wBFVRAU4+uBSt+Qgk+6EUydX94WlS62KoIxBLaNch6XhgYx08VBRDaNtEpXCf 1AaC5MMuFoVrhTRNCkOpu0z9oEjMDarIwF0crugu9CXPJdD8/YzJmfvr6rtPdqt1+l9s rSQaKDNhfyyB7lOnZttaOJzna4ZRrVT10PrzHVhYULIOId+HtwzwvUUX5znzDwwtHtY/ boKxLZFsJl5iWNpRHiRPDiyrMbaICFvknZO5z6i/X1tNDcQRm3HWNQxhzZiWzScFv+U0 ZvtA== X-Gm-Message-State: ALoCoQnpb5L4wf+SNACRTuiwk0GbT/bztQLzCerQIxyrz1rhR1uknrJxqB1WNNKmGomw/sc7w8QE MIME-Version: 1.0 X-Received: by 10.170.82.131 with SMTP id y125mr26734879yky.115.1435100535191; Tue, 23 Jun 2015 16:02:15 -0700 (PDT) Received: by 10.37.215.15 with HTTP; Tue, 23 Jun 2015 16:02:15 -0700 (PDT) X-Originating-IP: [81.48.1.193] In-Reply-To: <5589BF81.7080009@gmx.de> References: <84CC181F-E644-4075-B752-24B9C2D75AE2@gmail.com> <5589BF81.7080009@gmx.de> Date: Tue, 23 Jun 2015 23:02:15 +0000 Message-ID: To: Christoph Becker Cc: Tim Bezhashvyly , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Re: Typed Arrays in Scalar Types RFC From: danack@basereality.com (Dan Ackroyd) Tim Bezhashvyly wrote: > Please either throw stones at me or give me enough karma to post it. Sorry, I have neither the ability to give karma, nor a convenient pile of stones. Christoph Becker wrote: > Note that there is already , which has > been declined. The previous RFC was declined at least in part because of technical aspects of the implementation. In particular, because the 'typed array' wasn't implemented as a 'container'; instead the contents of the array would need to be checked each time it was passed from one function to another. i.e. for the functions: function fn1(Foo[] $fooArray) { fn2($fooArray); } function fn2(Foo[] $fooArray) { ... } When fn1() calls fn2(), even though the PHP engine could know that $fooArray contains only Foo elements, because of the way it was implemented, the whole array would be iterated through by the engine, comparing each entry to make sure that it is of type Foo. A new RFC would probably need to address at least that issue. It might also need to address a more general need for generics, rather than just the specific case of arrays with a single type. An alternative approach might be to introduce an RFC to make ArrayObject be usable wherever an array is required. Then people could implement a simple container themselves: class FooArray extends ArrayObject { function offsetSet($index, $newval) { if ($newval instanceof Foo) { throw new TypeError("$newval is not a Foo"); } parent::offsetSet($index, $newval); } } cheers Dan