Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71310 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30158 invoked from network); 20 Jan 2014 08:46:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2014 08:46:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.46 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.215.46 mail-la0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:59035] helo=mail-la0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/C5-02192-C72ECD25 for ; Mon, 20 Jan 2014 03:46:53 -0500 Received: by mail-la0-f46.google.com with SMTP id b8so5339643lan.33 for ; Mon, 20 Jan 2014 00:46:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=PsS649elu/hQ7UW7AFh4rYB8ltMq5eaqjSUaZDo8Zl0=; b=KkdkXsCqd9V6waeUR0JBwTvSha9SxOPxs4oKi/q0sMME4YM27ELDdoc/f/evEJMS/0 yfAPfZobosPpJJB7YDB8lPDKKu/lw319j+B6xWNOR7TdgjsvjdjS5QLtLELQvaeS1re5 U+UTiznuOPlB8OnAYaR2VjjABSVNCqBsHvdcNPu6mQrQj7B1AVWZOjoreQ+LZVU2SyuB IuadiqhgHaO53qID7Uujh7uqod+0AuPBDLZpeCyC/Em3DdgdRqWjwp67oAZAm5axyewB 88G7Wr8lw4Kpi5jnoxAAgmrhFhndOnFNmfejyU70PZuUSnFdmKWgvzJdchdvyvpsW5Si EvYw== MIME-Version: 1.0 X-Received: by 10.112.17.39 with SMTP id l7mr302359lbd.51.1390207609580; Mon, 20 Jan 2014 00:46:49 -0800 (PST) Received: by 10.112.35.134 with HTTP; Mon, 20 Jan 2014 00:46:49 -0800 (PST) In-Reply-To: <52DCD8B5.6060006@lerdorf.com> References: <004c01cf123d$35730870$a0591950$@tutteli.ch> <52D71748.1090402@googlemail.com> <52D71FAE.8030002@ajf.me> <005001cf124f$3a40df00$aec29d00$@tutteli.ch> <20140116110127.202079vzjsj76n7b@webmail.tutteli.ch> <0B.B1.24763.139B7D25@pb1.pair.com> <002001cf12da$2bfbda90$83f38fb0$@tutteli.ch> <52DCA3E7.80602@lerdorf.com> <52DCC067.9090603@garfieldtech.com> <52DCD8B5.6060006@lerdorf.com> Date: Mon, 20 Jan 2014 09:46:49 +0100 Message-ID: To: Rasmus Lerdorf Cc: Patrick Schaaf , Larry Garfield , internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Introducing "Array Of" RFC From: pierre.php@gmail.com (Pierre Joye) hi, On Mon, Jan 20, 2014 at 9:05 AM, Rasmus Lerdorf wrote: > On 1/19/14, 11:31 PM, Patrick Schaaf wrote: >> Regarding the N*M checking complexity, couldn't a little bit of memory >> alleviate the problem? >> >> For each array, have a "member type" pointer, initially NULL. >> >> When the member type needs to be checked for the first time, and that >> "member type" pointer is not already set, do an O(N) scan of the arrray, >> testing compatibility of all members against the hinted type. Error on >> mismatch, but when all members match, remember the type behind the "member >> type" pointer. >> >> When the member type needs to be checked and the "member type" pointer _is_ >> set, just compare it to the hinted type O(1). >> >> There must be some overhead when elements are added to an array. Either >> "when member type is set, forget it", or even "when member type is already >> set, check compatiility of the newly added element with the member type, >> and then remove member type on mismatch or keep it on match". > > This means every HT becomes larger now and every time you write to a HT > you at the very least need to do one extra comparison. We use HTs > everywhere, so this would have a performance impact on every script even > if you have absolutely no intention of ever using this feature. As I like this RFC for other reasons (type hinting extension), I tend to think that the use cases presented here can be done in a more efficient way. Someone else mentioned "collections" and it is exactly what it is all about. A collection could be an instance of a given class, which stores only one class type. It prevents on usage/function call checks and checks are done only when adding a member to the collection. On another note, and only as a note here as I really do not want to hijack this thread with another topic, the more I see this kind of RFCs the more I feel like we are heading to general or global type hinting supports. I think it could be the right time to actually decide what we want. It is getting critical as we keep adding stuff about type hinting, one after another, which may lead to inconsistencies and will prevent us to have a good type hinting mechanism in PHP. Cheers, -- Pierre @pierrejoye | http://www.libgd.org