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) == FAILURE) { return; } num_keys = zend_hash_num_elements(Z_ARRVAL_P(keys)); num_values = zend_hash_num_elements(Z_ARRVAL_P(values)); if (num_keys != 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=34857) 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=29972). 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ël. 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 problem. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php