Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66591 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98490 invoked from network); 11 Mar 2013 19:42:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2013 19:42:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain zend.com does not designate 209.85.219.53 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.219.53 mail-oa0-f53.google.com Received: from [209.85.219.53] ([209.85.219.53:43759] helo=mail-oa0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/A7-52104-D933E315 for ; Mon, 11 Mar 2013 14:42:22 -0500 Received: by mail-oa0-f53.google.com with SMTP id m1so4906558oag.26 for ; Mon, 11 Mar 2013 12:42:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=sYHvYgj8g1MLGLbtC8utDjDJc7d/oO7odOCjs9q5rjU=; b=fUy8zEZVdCzpSNFW45yG+eexrE0P9Q9iNfQQh2FhXWS/Ky4vQB36TLlNxiARc7S64y 6g45CkSHTJoPlh2VfefKK2iRwaJYDWL7e+kX1kXmLvC4T7XRBdp6cWVemO6q6f5Yng4r gHxsUjnPtP8v/t2vmOm7J+eYRkHP4QgnzpwMJUMdLefI2K/1BpaNpFhckvcW3yfGQ51N EF1Vbj+UFdQy3NkCn7exGb6LliK4ZyPAfunbe2QWuWG6nXNftFK78AzG3zkwxwwBQblT QG4Xj+WrPAv29SLR/LrL/iA3+AoOSXKEEgmzafbMkdJ7nvsvfEvTsSznfNgJUJPMYtFb 4Y6A== MIME-Version: 1.0 X-Received: by 10.182.221.4 with SMTP id qa4mr10083509obc.100.1363030938817; Mon, 11 Mar 2013 12:42:18 -0700 (PDT) Received: by 10.182.242.79 with HTTP; Mon, 11 Mar 2013 12:42:18 -0700 (PDT) In-Reply-To: References: Date: Mon, 11 Mar 2013 23:42:18 +0400 Message-ID: To: Nikita Popov Cc: PHP internals , Zeev Suraski , Andi Gutmans Content-Type: multipart/alternative; boundary=f46d044788fded810204d7ab5e9f X-Gm-Message-State: ALoCoQmU77yaDc1Mb2OyilkMn5jKSETZj0olLSvug6LCErKIfioEmv+D2ZOPO+V0ocTHQ4L0TnwlxMRW60ifyBW0xfkZW532J1roR89vZoeKLtAxglBkrw9C6K/HOauQLRfgUPVFrlsg Subject: Re: [PHP-DEV] Re: [VOTE] Allow non-scalar keys in foreach From: dmitry@zend.com (Dmitry Stogov) --f46d044788fded810204d7ab5e9f Content-Type: text/plain; charset=UTF-8 On Mon, Mar 11, 2013 at 10:27 PM, Nikita Popov wrote: > On Mon, Mar 11, 2013 at 9:50 AM, Dmitry Stogov wrote: > >> Hi Nikita, >> >> The patch looks good. I have just few comments >> >> - In ZEND_FE_FETCH handler PLAIN_OBJECT may have only STRING keys. I >> didn't get why you added unreachable code for INT and NULL. >> > > You are right about the NULL case, that can indeed not occur. But INT is > possible, e.g. consider this: > > foreach ((object) ['x','y','z'] as $k => $v) { > var_dump($k); > } > > this will give you keys int(0), int(1), int(2). > Agree. I missed it. > I'll remove the check for NULL. > > > - At first, I fought, that it might be a good idea to change >> zend_user_it_get_current_key() to return SUCCESS/FAILURE instead of >> returning IS_NULL that has a special meaning. But after looking into the >> FE_FETCH code before the commit I understood where this NULL came from. I >> know that NULL key may not appear for plain array and objects but I'm not >> sure about iterators and generators. Now IS_NULL keys may mean that >> iterator returned it directly IS_NULL or may be it was returned because of >> some error conditions. Probably it's not a problem. What do you think? >> > > In foreach IS_NULL can't occur in an error condition, because the loop is > already aborted when get_current_data provides NULL. IS_NULL can only > happen when its explicitly provided (or handlers are incorrectly coded). I > think the IS_NULL fallback is mainly important when the iterator is used > for other things (like a dual it), to be sure that it'll always work. I > don't think that it's important to distinguish between explicit NULL and > failure NULL. > Agree as well. > I have one more question: Right now I added the > zend_hash_get_current_key_zval API in zend_hash.c/h, which is a bit ugly > because it has a zval dependency (unlike all the other code in there) and > requires me to forward-declare the zval struct. Would it be better to move > this somewhere else, e.g. zend_API.c/h? If so, can I still keep the same > name (with the zend_hash_ prefix)? If I move it to zend_API, I won't be > able to do the IS_CONSISTENT check anymore, is that a problem? > I think we can move zval forward declaration (typedef struct _zval_struct zval;) from zend.h into zend_type.h. Thanks. Dmitry. --f46d044788fded810204d7ab5e9f--