Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49083 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95787 invoked from network); 16 Jul 2010 01:43:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2010 01:43:09 -0000 Authentication-Results: pb1.pair.com header.from=joel.perras@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=joel.perras@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.177 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.216.177 mail-qy0-f177.google.com Received: from [209.85.216.177] ([209.85.216.177:42552] helo=mail-qy0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 34/30-28935-C29BF3C4 for ; Thu, 15 Jul 2010 21:43:08 -0400 Received: by qyk1 with SMTP id 1so328366qyk.8 for ; Thu, 15 Jul 2010 18:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=nUjUVO32qlogJZVorwTPiL4oqR9kyUzilbiPZid9O8c=; b=sjWUBm3Jtb6nymfULVQZegqEG1qqyrcT4eroAbSSbyo/DmIpIkZTEbGSx0fjyCx/Vy c05yyev1+HH9rtetxf90ka/1oFRDPNuN69MhEtW388ZIxrQlmr5L8EDXdo0ZF42jH7+D J6Jl8DYrp4wEgv1Dxfay0xPY5WTx/Ey4fnsr0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; b=NlVczIpmgKgDQBoneORzwAQa83GXFeCqyrtUDtUQTkBMHFTnr5M2nWGFJ6Es4WbLaa cSiryLDs4GPAIi0gLoZcDCe4Besua7ZzrnAsIZ9V7KFcNDMet9ShSCZNWzqzSRCpz6fb EYK8MBkkZRL8+xpl/Pg6mtcqKcI2J20RyDPS0= Received: by 10.224.114.211 with SMTP id f19mr286158qaq.228.1279244586167; Thu, 15 Jul 2010 18:43:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.100.143 with HTTP; Thu, 15 Jul 2010 18:42:46 -0700 (PDT) Date: Thu, 15 Jul 2010 21:42:46 -0400 Message-ID: To: internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Unintuitive array_combine() behaviour From: joel.perras@gmail.com (Joel Perras) 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) { zval *values, *keys; HashPosition pos_values, pos_keys; zval **entry_keys, **entry_values; int num_keys, num_values; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aa", &keys, &values) =3D=3D FAILURE) { return; } num_keys =3D zend_hash_num_elements(Z_ARRVAL_P(keys)); num_values =3D zend_hash_num_elements(Z_ARRVAL_P(values)); if (num_keys !=3D num_values) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Both parameters should have an equal number of elements"); RETURN_FALSE; } if (!num_keys) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Both parameters should have at least 1 element"); RETURN_FALSE; } // [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? --=20 I do know everything, just not all at once. It's a virtual memory problem.