Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66596 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72675 invoked from network); 12 Mar 2013 16:43:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2013 16:43:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.169 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.169 mail-ob0-f169.google.com Received: from [209.85.214.169] ([209.85.214.169:59611] helo=mail-ob0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CF/0D-19967-53B5F315 for ; Tue, 12 Mar 2013 11:43:33 -0500 Received: by mail-ob0-f169.google.com with SMTP id ta14so40584obb.28 for ; Tue, 12 Mar 2013 09:43:30 -0700 (PDT) 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=xTXucRkGAXmNKBJgNf/K5Z6EA8fWAEXH6BPfggWdo40=; b=QFxy4NWdYbqLzI/Q6tg3lclSYDvNruytTxNBZTB7REvVWRn/Oq6esFz4bcs4jvhLRB xZQ61RtspWHN0hv8bgw7skx70dXUpOykG6aQGM7MP1SFKfI5F5+kd+kLFbcnoJxXlxZ5 bQxK6oPDJ6/8gdG5xAq+myRuiIz7YxT9NpWPBqLn+AXxDOb0BxFitIWZ8mc5jXw849In EqjDTNg4wyFY6wMBnxML7YU3cyCxziAB4xpOnizEUO+DeOFzdBhXDKWJErhbysS6oVup wNwc3/biGwR8eD1JN3uCHRUMbuRGeK1ldXmHYUSfiWqpJvFY4WykW6MHiePGPPc/jMu6 l6QA== MIME-Version: 1.0 X-Received: by 10.60.10.102 with SMTP id h6mr12751882oeb.14.1363106610313; Tue, 12 Mar 2013 09:43:30 -0700 (PDT) Received: by 10.182.49.136 with HTTP; Tue, 12 Mar 2013 09:43:30 -0700 (PDT) In-Reply-To: References: Date: Tue, 12 Mar 2013 17:43:30 +0100 Message-ID: To: Dmitry Stogov Cc: PHP internals , Zeev Suraski , Andi Gutmans Content-Type: multipart/alternative; boundary=e89a8fb1f4ae4c80c304d7bcfd3a Subject: Re: [PHP-DEV] Re: [VOTE] Allow non-scalar keys in foreach From: nikita.ppv@gmail.com (Nikita Popov) --e89a8fb1f4ae4c80c304d7bcfd3a Content-Type: text/plain; charset=ISO-8859-1 On Mon, Mar 11, 2013 at 8:42 PM, Dmitry Stogov wrote: > > > 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. > I now merged the changeset in https://github.com/php/php-src/commit/fcc6611de9054327441786e52444b5f8eecdd525(for PHP-5.5 and master) with the forward declaration moved. Also updated some array functions to use the new get_current_key_zval function :) Nikita --e89a8fb1f4ae4c80c304d7bcfd3a--