Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62415 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8446 invoked from network); 23 Aug 2012 06:23:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Aug 2012 06:23:41 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:39739] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/12-29773-A6CC5305 for ; Thu, 23 Aug 2012 02:23:38 -0400 Received: by weyr1 with SMTP id r1so233530wey.29 for ; Wed, 22 Aug 2012 23:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=fqvMPw9XtDIbk9WHJHYHI5w17kLTMmVwIdt7vEj0ZGc=; b=sZTmtVdnn3MdC8+y6PfMdQdLLMWL3ikkLtwfFLhmQ4Cy/SllXDyxxcnLJsE9wuFIYy ddpZrK+3uO96Etgjw29DZnECamJ+QdkofYNF9KKWuXqhHJap6i/unr5lm/BCyl5ixDkz rzO/YICeJDRAtw5x0dp8QNpX49PFhU4qSUlemnHA+wIKBl4v2Rief8kny4l7EownP5AO s3Zimpk4fonkKMfZXjlrNf0HekGG5oMiab+Z65ce5P6OoUsdT/pOtPDVrE2JyQZfWACG iuZtqZIwm2amUOZ91Lcc8ricF8o/8CNA8Mc2XT3eON95X14reAGgt0NtQGgfLR7KUWfY 9ffA== Received: by 10.180.74.33 with SMTP id q1mr12211888wiv.4.1345703015283; Wed, 22 Aug 2012 23:23:35 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.223.86.201 with HTTP; Wed, 22 Aug 2012 23:22:55 -0700 (PDT) In-Reply-To: <2wttof5yc8vy3540vghjx052.1345618254409@email.android.com> References: <2wttof5yc8vy3540vghjx052.1345618254409@email.android.com> Date: Thu, 23 Aug 2012 15:22:55 +0900 X-Google-Sender-Auth: gPV3ZGMv8XBbD062s-ZTRaHaPeQ Message-ID: To: Andrew Faulds Cc: Levi Morrison , Rasmus Schultz , internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] removing an item from an array From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi, 2012/8/22 Andrew Faulds : > Um, Yasuo, have you looked at array_walk implementation and ascertained it > is safe to change array structure while using it? > > Because I'm worried you're changing docs without doing so. Simply deleting current element is safe. It's done in everywhere in PHP. It's just like deleting elements with zend hash. array_walk() could bite users. If programmer sort or delete element to be processed next, it causes problem. PHP programmer will not sort or delete next element to processed while working with zend hash, but average PHP users do not care about internal. I finally understand why people use array_filter() to delete elements and I think we should have array_udelete() since the API is much safer than array_walk(). Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net > > -- > Sent from Samsung Mobile > Andrew Faulds > http://ajf.me/ > > > > Yasuo Ohgaki wrote: > > > Hi, > > 2012/8/22 Levi Morrison : >> On Tue, Aug 21, 2012 at 7:45 PM, Yasuo Ohgaki wrote: >>> >>> Hi, >>> >>> 2012/8/16 Rasmus Schultz : >>> > How come there is no straight-foward obvious way to simply remove a >>> > given >>> > value from an array? >>> > >>> > Just look at the number of horrible ways people solve this obvious >>> > problem: >>> > >>> > >>> > http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key >>> > >>> > Shouldn't we have something simple, like: >>> > >>> > array_remove($array, $value) : array (returns a new array) >>> > >>> > and/or >>> > >>> > array_delete(&$array, $value) : bool (modifies array directly) >>> > >>> > ? >>> >>> It was amazing that this thread has close to 90 mails. >>> >>> I've added some use cases of array_udelete() to wiki, since >>> some people fails to see how it could be useful. I also bring >>> back to array_walk() version of equivalent example. I just >>> don't see any reason why we should replace it with slower >>> foreach() version. >>> >>> I think the RFC page is almost complete. >>> >>> https://wiki.php.net/rfc/array_delete >>> >>> Any more comments? >>> >>> -- >>> Yasuo Ohgaki >>> yohgaki@ohgaki.net >> >> Take a look at: >> >> http://php.net/manual/en/function.array-walk.php#refsect1-function.array-walk-parameters >> >> Look at funcname parameter. Notice: >>> Only the values of the array may potentially be changed; its structure >>> cannot be altered, i.e., the programmer cannot add, unset or reorder >>> elements. If the callback does not respect this requirement, the behavior of >>> this function is undefined, and unpredictable. >> >> I'm just going to change the behavior back when you switch it to >> array_walk. It's less clear and technically undefined. > > Ok, then my commit to the doc was outstanding still. > Old PHP was behaved badly with reference variables. > I'll remove obsolete statement. > > I'll fix it later. > Thank you. > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >