Re: New Function: is_scalar

From: Date: Sat, 16 Dec 2000 04:35:44 +0000
Subject: Re: New Function: is_scalar
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-41563@lists.php.net to get a copy of this message
I recently submitted a patch for review - given that there was no feedback, I assume that all is well with it. ;) Unless someone objects, I will submit the modifications to the codebase tomorrow at about 1400 GMT / 1600 Israeli time. Once again - for your viewing pleasure - here is my original message: Hello All, I would like add a trivial little function that tests to see if a value is a scalar. I have written the function and tested it on Mandrake 7.1 with good results. (The function seemed very straightforward to implement - I based it on is_numeric()) Does anyone object to this function being added to the codebase? Personally, I would use this function to replace code snippets like: if (is_array ($foo) || is_object ($foo) || is_resource ($foo)) return FALSE; Would anyone care to quickly review my patch and ensure that it does not do anything silly. :) --- basic_functions.h Wed Nov 29 08:37:38 2000 +++ basic_functions.h.zak Thu Dec 14 16:09:17 2000 @@ -73,6 +73,7 @@ PHP_FUNCTION(is_long); PHP_FUNCTION(is_double); PHP_FUNCTION(is_numeric); +PHP_FUNCTION(is_scalar); PHP_FUNCTION(is_string); PHP_FUNCTION(is_array); PHP_FUNCTION(is_object); --- basic_functions.c Wed Dec 13 16:02:09 2000 +++ basic_functions.c.zak Thu Dec 14 16:09:10 2000 @@ -319,6 +319,7 @@ PHP_FE(is_double, first_arg_allow_ref) PHP_FALIAS(is_real, is_double, first_arg_allow_ref) PHP_FE(is_numeric, NULL) + PHP_FE(is_scalar, NULL) PHP_FE(is_string, first_arg_allow_ref) PHP_FE(is_array, first_arg_allow_ref) PHP_FE(is_object, first_arg_allow_ref) @@ -1403,6 +1404,35 @@ } } /* }}} */ + + +/* {{{ proto bool is_scalar(mixed value) + Returns true if value is a scalar value */ +PHP_FUNCTION(is_scalar) +{ + zval **arg; + int result; + + if (ZEND_NUM_ARGS() !=1 || zend_get_parameters_ex(1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + switch (Z_TYPE_PP(arg)) { + case IS_BOOL: + case IS_DOUBLE: + case IS_LONG: + case IS_NULL: + case IS_STRING: + RETURN_TRUE; + break; + + default: + RETURN_FALSE; + break; + } +} +/* }}} */ + /* 1st arg = error message Thanks! --zak PS. I do realize that the codebase has changed since I did the diffs -- I will make sure to update the most recent version of the files before I commit anything.

« previous php.dev (#41563) next »