Re: cvs: php4 /ext/standard array.c basic_functions.c php_array.h
| From: | David Croft | Date: | Mon, 30 Apr 2001 04:19:33 +0000 |
| Subject: | Re: cvs: php4 /ext/standard array.c basic_functions.c php_array.h | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-5371@lists.php.net to get a copy of this message | ||
$a = array('hello' => null);
isset($a['hello']); // false
key_exists('hello', $a); // true
--
|> /+\ \| | |>
David Croft
Infotrek
On Mon, 30 Apr 2001, Andi Gutmans wrote:
> Why not use isset()? How is this different? (I know one reason why it's
> different but I'm curious what difference you see).
>
> Andi
>
> At 04:06 AM 4/30/2001 +0000, David Croft wrote:
> >david Sun Apr 29 21:06:10 2001 EDT
> >
> > Modified files:
> > /php4/ext/standard array.c basic_functions.c php_array.h
> > Log:
> > @ - Added key_exists() to check if a given key or index exists in an
> > @ array or object (David Croft)
> > Added key_exists() to check if a given key or index exists in an array
> > or object
> >
> >
> >Index: php4/ext/standard/array.c
> >diff -u php4/ext/standard/array.c:1.107 php4/ext/standard/array.c:1.108
> >--- php4/ext/standard/array.c:1.107 Mon Apr 2 06:20:16 2001
> >+++ php4/ext/standard/array.c Sun Apr 29 21:06:09 2001
> >@@ -21,7 +21,7 @@
> > +----------------------------------------------------------------------+
> > */
> >
> >-/* $Id: array.c,v 1.107 2001/04/02 13:20:16 andrei Exp $ */
> >+/* $Id: array.c,v 1.108 2001/04/30 04:06:09 david Exp $ */
> >
> > #include "php.h"
> > #include "php_ini.h"
> >@@ -3074,6 +3074,44 @@
> > }
> > /* }}} */
> >
> >+
> >+/* {{{ proto bool key_exists(mixed key, array search)
> >+ Checks if the given key or index exists in the array */
> >+PHP_FUNCTION(key_exists)
> >+{
> >+ zval **key, /* key to check for */
> >+ **array; /* array to check
> >in */
> >+
> >+ if (ZEND_NUM_ARGS() != 2 ||
> >+ zend_get_parameters_ex(ZEND_NUM_ARGS(), &key, &array) ==
> >FAILURE) {
> >+ WRONG_PARAM_COUNT;
> >+ }
> >+
> >+ if (Z_TYPE_PP(array) != IS_ARRAY && Z_TYPE_PP(array) != IS_OBJECT) {
> >+ php_error(E_WARNING, "Wrong datatype for second argument
> >in call to %s", get_active_function_name());
> >+ RETURN_FALSE;
> >+ }
> >+
> >+ switch (Z_TYPE_PP(key)) {
> >+ case IS_STRING:
> >+ if (zend_hash_exists(HASH_OF(*array),
> >Z_STRVAL_PP(key), Z_STRLEN_PP(key)+1)) {
> >+ RETURN_TRUE;
> >+ }
> >+ RETURN_FALSE;
> >+
> >+ case IS_LONG:
> >+ if (zend_hash_index_exists(HASH_OF(*array),
> >Z_LVAL_PP(key))) {
> >+ RETURN_TRUE;
> >+ }
> >+ RETURN_FALSE;
> >+
> >+ default:
> >+ php_error(E_WARNING, "Wrong datatype for first
> >argument in call to %s", get_active_function_name());
> >+ RETURN_FALSE;
> >+ }
> >+
> >+}
> >+/* }}} */
> >
> > /*
> > * Local variables:
> >Index: php4/ext/standard/basic_functions.c
> >diff -u php4/ext/standard/basic_functions.c:1.325
> >php4/ext/standard/basic_functions.c:1.326
> >--- php4/ext/standard/basic_functions.c:1.325 Tue Apr 17 10:08:03 2001
> >+++ php4/ext/standard/basic_functions.c Sun Apr 29 21:06:09 2001
> >@@ -17,7 +17,7 @@
> > +----------------------------------------------------------------------+
> > */
> >
> >-/* $Id: basic_functions.c,v 1.325 2001/04/17 17:08:03 wez Exp $ */
> >+/* $Id: basic_functions.c,v 1.326 2001/04/30 04:06:09 david Exp $ */
> >
> > #include "php.h"
> > #include "php_main.h"
> >@@ -588,6 +588,7 @@
> > PHP_FE(array_sum,
> > NULL)
> > PHP_FE(array_filter,
> > NULL)
> > PHP_FE(array_map,
> > NULL)
> >+ PHP_FE(key_exists,
> > NULL)
> >
> > /* aliases from array.c */
> > PHP_FALIAS(pos, current,
> > first_arg_force_ref)
> >Index: php4/ext/standard/php_array.h
> >diff -u php4/ext/standard/php_array.h:1.24 php4/ext/standard/php_array.h:1.25
> >--- php4/ext/standard/php_array.h:1.24 Mon Mar 19 13:20:02 2001
> >+++ php4/ext/standard/php_array.h Sun Apr 29 21:06:09 2001
> >@@ -19,7 +19,7 @@
> > +----------------------------------------------------------------------+
> > */
> >
> >-/* $Id: php_array.h,v 1.24 2001/03/19 21:20:02 andrei Exp $ */
> >+/* $Id: php_array.h,v 1.25 2001/04/30 04:06:09 david Exp $ */
> >
> > #ifndef PHP_ARRAY_H
> > #define PHP_ARRAY_H
> >@@ -77,6 +77,7 @@
> > PHP_FUNCTION(array_sum);
> > PHP_FUNCTION(array_filter);
> > PHP_FUNCTION(array_map);
> >+PHP_FUNCTION(key_exists);
> >
> > HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **);
> > PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive);
> >
> >
> >
> >--
> >PHP CVS Mailing List (http://www.php.net/)
> >To unsubscribe, e-mail: php-cvs-unsubscribe@lists.php.net
> >For additional commands, e-mail: php-cvs-help@lists.php.net
> >To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>