CVS update: php4/ext/standard
| From: | andrey | Date: | Mon, 07 Jun 1999 18:52:20 +0000 |
| Subject: | CVS update: php4/ext/standard | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-1378@lists.php.net to get a copy of this message | ||
Date: Monday June 7, 1999 @ 14:52
Author: andrey
Update of /repository/php4/ext/standard
In directory php:/tmp/cvs-serv5584/ext/standard
Modified Files:
basic_functions.c basic_functions.h
Log Message:
Don't set is_ref in _phpi_splice()
More checking in array_merge()
Added keys() and values() array functions.
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.27 php4/ext/standard/basic_functions.c:1.28
--- php4/ext/standard/basic_functions.c:1.27 Sun Jun 6 11:00:49 1999
+++ php4/ext/standard/basic_functions.c Mon Jun 7 14:52:20 1999
@@ -304,6 +304,8 @@
PHP_FE(splice, first_arg_force_ref)
PHP_FE(slice, NULL)
PHP_FE(array_merge, NULL)
+ PHP_FE(keys, NULL)
+ PHP_FE(values, NULL)
{NULL, NULL, NULL}
};
@@ -2497,7 +2499,6 @@
and copy it into the output hash */
for (i=0; i<list_count; i++) {
entry = list[i];
- entry->is_ref = 1;
entry->refcount++;
zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL);
}
@@ -2855,7 +2856,10 @@
array_init(return_value);
for (i=0; i<argc; i++) {
- convert_to_array(args[i]);
+ if (args[i]->type != IS_ARRAY) {
+ zend_error(E_WARNING, "Skipping argument #%d to array_merge(), since it's not an
array", i+1);
+ continue;
+ }
hash = args[i]->value.ht;
zend_hash_internal_pointer_reset(hash);
@@ -2880,6 +2884,93 @@
}
efree(args);
+}
+/* }}} */
+
+
+/* {{{ proto array keys(array input)
+ Return just the keys from the input array */
+PHP_FUNCTION(keys)
+{
+ zval *input, /* Input array */
+ **entry, /* An entry in the input array */
+ *new_val; /* New value */
+ char *string_key; /* String key */
+ ulong num_key; /* Numeric key */
+
+ /* Get arguments and do error-checking */
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, ARG_COUNT(ht), &input) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ if (input->type != IS_ARRAY) {
+ zend_error(E_WARNING, "Argument to keys() should be an array");
+ return;
+ }
+
+ /* Initialize return array */
+ array_init(return_value);
+
+ /* Go through input array and add keys to the return array */
+ zend_hash_internal_pointer_reset(input->value.ht);
+ while(zend_hash_get_current_data(input->value.ht, (void **)&entry) == SUCCESS) {
+ new_val = (zval *)emalloc(sizeof(zval));
+ new_val->is_ref = 0;
+ new_val->refcount = 1;
+
+ switch (zend_hash_get_current_key(input->value.ht, &string_key, &num_key)) {
+ case HASH_KEY_IS_STRING:
+ new_val->type = IS_STRING;
+ new_val->value.str.val = string_key;
+ new_val->value.str.len = strlen(string_key);
+ zend_hash_next_index_insert(return_value->value.ht, &new_val,
+ sizeof(zval *), NULL);
+ break;
+
+ case HASH_KEY_IS_LONG:
+ new_val->type = IS_LONG;
+ new_val->value.lval = num_key;
+ zend_hash_next_index_insert(return_value->value.ht, &new_val,
+ sizeof(zval *), NULL);
+ break;
+ }
+
+ zend_hash_move_forward(input->value.ht);
+ }
+}
+/* }}} */
+
+
+/* {{{ proto array values(array input)
+ Return just the values from the input array */
+PHP_FUNCTION(values)
+{
+ zval *input, /* Input array */
+ **entry; /* An entry in the input array */
+
+ /* Get arguments and do error-checking */
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, ARG_COUNT(ht), &input) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ if (input->type != IS_ARRAY) {
+ zend_error(E_WARNING, "Argument to values() should be an array");
+ return;
+ }
+
+ /* Initialize return array */
+ array_init(return_value);
+
+ /* Go through input array and add values to the return array */
+ zend_hash_internal_pointer_reset(input->value.ht);
+ while(zend_hash_get_current_data(input->value.ht, (void **)&entry) == SUCCESS) {
+
+ (*entry)->refcount++;
+ zend_hash_next_index_insert(return_value->value.ht, entry,
+ sizeof(zval *), NULL);
+
+ zend_hash_move_forward(input->value.ht);
+ }
}
/* }}} */
Index: php4/ext/standard/basic_functions.h
diff -u php4/ext/standard/basic_functions.h:1.8 php4/ext/standard/basic_functions.h:1.9
--- php4/ext/standard/basic_functions.h:1.8 Sat Jun 5 17:19:25 1999
+++ php4/ext/standard/basic_functions.h Mon Jun 7 14:52:20 1999
@@ -29,7 +29,7 @@
*/
-/* $Id: basic_functions.h,v 1.8 1999/06/05 21:19:25 andrey Exp $ */
+/* $Id: basic_functions.h,v 1.9 1999/06/07 18:52:20 andrey Exp $ */
#ifndef _BASIC_FUNCTIONS_H
#define _BASIC_FUNCTIONS_H
@@ -129,6 +129,8 @@
PHP_FUNCTION(splice);
PHP_FUNCTION(slice);
PHP_FUNCTION(array_merge);
+PHP_FUNCTION(keys);
+PHP_FUNCTION(values);
#if HAVE_PUTENV
typedef struct {