Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49545 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70959 invoked from network); 26 Aug 2010 17:07:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Aug 2010 17:07:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=joel.perras@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=joel.perras@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: joel.perras@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bw0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:52061] helo=mail-bw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FD/4F-26066-85F967C4 for ; Thu, 26 Aug 2010 13:07:36 -0400 Received: by bwz8 with SMTP id 8so121195bwz.29 for ; Thu, 26 Aug 2010 10:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=z48HyrsoAb7mfBU3KhCqZrjkH5oT2KiDM2wZOc3poQI=; b=KL7sdZm4ZkN+q7JAxvPQNT5GbiGsZf4o4pbz4LRYTarJPGmSUSEKxCeMWYklsC9RVk 5r42MuAn9U/Py1kV70MtPP6t+FSrGXZazi9UEOByKmOynR8eX3/AVEf6A0AGTbBmZzC3 pKjVv/Q5Ns2bHaxKnWDdCsm8vQtc8l+axJqqM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=dCrEhBipva2KZ59jdii5RXcbOxJfb64Tus603NWpvtQ/Dmyi2NIximBwbpgcU/lAYP NrYtL533GYVjRB1kck5mBaJatq8oDCEqIdn1wMHS2nAz+zSzMXc1us8dsMU2amezoDLO dQhc1IVsla68l92j64VgklTIKRb+Glq7g8KWw= Received: by 10.204.53.140 with SMTP id m12mr6431292bkg.195.1282842452246; Thu, 26 Aug 2010 10:07:32 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.84.6 with HTTP; Thu, 26 Aug 2010 10:07:12 -0700 (PDT) In-Reply-To: References: Date: Thu, 26 Aug 2010 13:07:12 -0400 Message-ID: To: RQuadling@googlemail.com Cc: internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Unintuitive array_combine() behaviour From: joel.perras@gmail.com (Joel Perras) Since there didn't seem to be anyone who disagreed on the odd behaviour of array_combine() with empty arrays as arguments, I've written up a patch for this and attached it to the existing feature change/request report: Report: http://bugs.php.net/bug.php?id=3D34857 Patch: http://paste.roguecoders.com/p/16e1e953e8b1890bcaaba00eb8408dd7.txt If someone with the appropriate karma could review this and commit it to trunk, that would be grand. Thanks, Jo=C3=ABl. On Fri, Jul 16, 2010 at 5:52 AM, Richard Quadling wro= te: > On 16 July 2010 02:42, Joel Perras wrote: >> array_combine(array(), array()) triggers an E_WARNING and returns >> false, instead of simply returning an empty array with no triggered >> warning. >> >> This is not a bug, but was intentionally written as such - see >> ext/standard/array.c around lines 4480-4483 in the 5.3 branch in the >> current svn HEAD: >> >> >> PHP_FUNCTION(array_combine) >> { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0zval *values, *keys; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0HashPosition pos_values, pos_keys; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0zval **entry_keys, **entry_values; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0int num_keys, num_values; >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0if (zend_parse_parameters(ZEND_NUM_ARGS() TSR= MLS_CC, "aa", &keys, >> &values) =3D=3D FAILURE) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0num_keys =3D zend_hash_num_elements(Z_ARRVAL_= P(keys)); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0num_values =3D zend_hash_num_elements(Z_ARRVA= L_P(values)); >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0if (num_keys !=3D num_values) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0php_error_docref(= NULL TSRMLS_CC, E_WARNING, "Both parameters should >> have an equal number of elements"); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0RETURN_FALSE; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!num_keys) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0php_error_docref(= NULL TSRMLS_CC, E_WARNING, "Both parameters should >> have at least 1 element"); >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0RETURN_FALSE; >> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> >> // [snip] >> >> >> There is currently one open ticket regarding this behaviour >> (http://bugs.php.net/bug.php?id=3D34857) from 2005, as well as a ticket >> that was closed, stating that the incorrect E_WARNING message was >> fixed (http://bugs.php.net/bug.php?id=3D29972). This behaviour is also >> documented on http://php.net/array_combine . >> >> So, it's easy to see that this has been around for a while. However, I >> don't think this behaviour is intuitive or very logical. Am I missing >> something obvious? >> >> Thanks, >> Jo=C3=ABl. >> >> P.S. >> I've searched back to about 2004 in the php-internals list to see if >> this topic has come up before, but came up empty. If this has already >> been discussed ad nauseam, could someone please link me to the >> relevant posts? >> >> -- >> I do know everything, just not all at once. It's a virtual memory proble= m. >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > [1] contains the initial submission of this function. > > It was commited on Jan 13 18:12:23 2003 UTC (7 years, 6 months ago) by an= drey > > "added array_combine(). > Creates an array by using the elements of the first parameter as keys and > the elements of the second as correspoding keys. Error is thrown in case > the arrays has different number of elements. Number of elements 0 is not > valid for both parameters." > > As a lurker here, generating an error does seem odd. It forces > addition userland work for seemingly no benefit. > > So a +1 for array() =3D=3D=3D array_combine(array(), array()) > > Regards, > > Richard. > > [1] http://svn.php.net/viewvc?view=3Drevision&revision=3D111688 > --=20 I do know everything, just not all at once. It's a virtual memory problem. You should follow me on Twitter: http://twitter.com/jperras