Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65973 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3769 invoked from network); 19 Feb 2013 17:36:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2013 17:36:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.41 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.219.41 mail-oa0-f41.google.com Received: from [209.85.219.41] ([209.85.219.41:62676] helo=mail-oa0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/80-17768-E28B3215 for ; Tue, 19 Feb 2013 12:36:46 -0500 Received: by mail-oa0-f41.google.com with SMTP id i10so7286420oag.14 for ; Tue, 19 Feb 2013 09:36:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=qRjrf3nzuAjaqtCCfKvTuGvhQB+SoOccJPL9QA4tkYo=; b=wjC6Rln3Hqz3ru7xQrMoqq1u/OArl/tCgK/r3MoR0gY8S+g3e4MMhWio02FmYLIwaU 7lWz/357OmSi+OclrvoIwB7B8kRaDnbqVEaRGGoVtCpb2MXaGkmhYwurKtxX4TgLPi60 gywiVQNs+aZBv1Enl/uA1w4n+TaRNqWs4P+VTm9yKONrVgpr3YGUzU/i/rQOtVNWDJ3K 34ArxxULkz+aU+ZWUmZuRfgW5Q5EAbg5qIjCIv6hKPP+Ms0dA4WL1vKPqjSwWtYH8rKy U23al8Gjg47oEahUrvNV03EXE7xkHu5KvaJkHFXeFIhU6fkWZTHpHjNe5T4APygPoiLD Loaw== MIME-Version: 1.0 X-Received: by 10.60.31.113 with SMTP id z17mr7731071oeh.37.1361295403464; Tue, 19 Feb 2013 09:36:43 -0800 (PST) Received: by 10.76.24.234 with HTTP; Tue, 19 Feb 2013 09:36:43 -0800 (PST) In-Reply-To: References: Date: Tue, 19 Feb 2013 10:36:43 -0700 Message-ID: To: Etienne Kneuss Cc: Derick Rethans , Nikita Popov , PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [RFC] Allow non-scalar keys in foreach From: morrison.levi@gmail.com (Levi Morrison) >> > I think the warning can stay as-is, __toString is not necessarily >> > available so casting to string in all occasions is probably not what >> > we want. >> >> I think it should cast to a string if possible. You are now making >> iterator_to_array not work with the new feature, and I find that a bit >> silly. Whether it should be __toString (or __toKey) I don't really care, >> but this new support for objects should be supported everywhere (and >> that includes iterator_to_array). >> > > I think this RFC is orthogonal to iterator_to_array supporting conversions > from objects to keys. > > $array[$obj] = 42; does not call __toString (or __toKey), it throws a > catchable fatal. IMO it would be inconsistent if iterator_to_array > gracefully accepted objects as keys. Personally I think the real problem here is that `iterator_to_array` should *not* copy keys by default. However, what's done is done and we need to thoughtfully consider this situation. You already CAN return objects from an iterator; you just can't use it in a foreach. If you try to use that iterator in `iteator_to_array` you get a lovely warning: Warning: Illegal type returned from %s::key() in %s on line %d I'm all for *not* changing that behavior; if they want it ignore keys then they can pass `false` as a second parameter to `iterator_to_array`.