Back to index

php5  5.3.10
Functions
php_type.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 PHP_FUNCTION (intval)
 PHP_FUNCTION (floatval)
 PHP_FUNCTION (strval)
 PHP_FUNCTION (gettype)
 PHP_FUNCTION (settype)
 PHP_FUNCTION (is_null)
 PHP_FUNCTION (is_resource)
 PHP_FUNCTION (is_bool)
 PHP_FUNCTION (is_long)
 PHP_FUNCTION (is_float)
 PHP_FUNCTION (is_numeric)
 PHP_FUNCTION (is_string)
 PHP_FUNCTION (is_array)
 PHP_FUNCTION (is_object)
 PHP_FUNCTION (is_scalar)
 PHP_FUNCTION (is_callable)

Function Documentation

PHP_FUNCTION ( intval  )

Definition at line 134 of file type.c.

{
       zval **num;
       long arg_base;
       int base;

       switch (ZEND_NUM_ARGS()) {
              case 1:
                     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) {
                            return;
                     }
                     base = 10;
                     break;

              case 2:
                     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zl", &num, &arg_base) == FAILURE) {
                            return;
                     }
                     base = arg_base;
                     break;

              default:
                     WRONG_PARAM_COUNT;
       }

       RETVAL_ZVAL(*num, 1, 0);
       convert_to_long_base(return_value, base);
}

Here is the call graph for this function:

PHP_FUNCTION ( floatval  )

Definition at line 166 of file type.c.

{
       zval **num;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) {
              return;
       }

       RETVAL_ZVAL(*num, 1, 0);
       convert_to_double(return_value);
}

Here is the call graph for this function:

PHP_FUNCTION ( strval  )

Definition at line 181 of file type.c.

{
       zval **num, *tmp;
       zval expr_copy;
       int use_copy;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &num) == FAILURE) {
              return;
       }

       zend_make_printable_zval(*num, &expr_copy, &use_copy);
       if (use_copy) {
              tmp = &expr_copy;
              RETVAL_ZVAL(tmp, 0, 0);
       } else {
              RETVAL_ZVAL(*num, 1, 0);
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( gettype  )

Definition at line 26 of file type.c.

{
       zval **arg;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }

       switch (Z_TYPE_PP(arg)) {
              case IS_NULL:
                     RETVAL_STRING("NULL", 1);
                     break;

              case IS_BOOL:
                     RETVAL_STRING("boolean", 1);
                     break;

              case IS_LONG:
                     RETVAL_STRING("integer", 1);
                     break;

              case IS_DOUBLE:
                     RETVAL_STRING("double", 1);
                     break;
       
              case IS_STRING:
                     RETVAL_STRING("string", 1);
                     break;
       
              case IS_ARRAY:
                     RETVAL_STRING("array", 1);
                     break;

              case IS_OBJECT:
                     RETVAL_STRING("object", 1);
              /*
                 {
                 char *result;
                 int res_len;

                 res_len = sizeof("object of type ")-1 + Z_OBJCE_P(arg)->name_length;
                 spprintf(&result, 0, "object of type %s", Z_OBJCE_P(arg)->name);
                 RETVAL_STRINGL(result, res_len, 0);
                 }
               */
                     break;

              case IS_RESOURCE:
                     {
                            char *type_name;
                            type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(arg) TSRMLS_CC);
                            if (type_name) {
                                   RETVAL_STRING("resource", 1);
                                   break;
                            }
                     }

              default:
                     RETVAL_STRING("unknown type", 1);
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( settype  )

Definition at line 91 of file type.c.

{
       zval **var;
       char *type;
       int type_len = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zs", &var, &type, &type_len) == FAILURE) {
              return;
       }

       if (!strcasecmp(type, "integer")) {
              convert_to_long(*var);
       } else if (!strcasecmp(type, "int")) {
              convert_to_long(*var);
       } else if (!strcasecmp(type, "float")) {
              convert_to_double(*var);
       } else if (!strcasecmp(type, "double")) { /* deprecated */
              convert_to_double(*var);
       } else if (!strcasecmp(type, "string")) {
              convert_to_string(*var);
       } else if (!strcasecmp(type, "array")) {
              convert_to_array(*var);
       } else if (!strcasecmp(type, "object")) {
              convert_to_object(*var);
       } else if (!strcasecmp(type, "bool")) {
              convert_to_boolean(*var);
       } else if (!strcasecmp(type, "boolean")) {
              convert_to_boolean(*var);
       } else if (!strcasecmp(type, "null")) {
              convert_to_null(*var);
       } else if (!strcasecmp(type, "resource")) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot convert to resource type");
              RETURN_FALSE;
       } else {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid type");
              RETURN_FALSE;
       }
       RETVAL_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( is_null  )

Definition at line 237 of file type.c.

Here is the call graph for this function:

PHP_FUNCTION ( is_resource  )

Definition at line 245 of file type.c.

Here is the call graph for this function:

PHP_FUNCTION ( is_bool  )

Definition at line 253 of file type.c.

Here is the call graph for this function:

PHP_FUNCTION ( is_long  )

Definition at line 261 of file type.c.

Here is the call graph for this function:

PHP_FUNCTION ( is_float  )

Definition at line 269 of file type.c.

Here is the call graph for this function:

PHP_FUNCTION ( is_numeric  )

Definition at line 301 of file type.c.

{
       zval **arg;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }

       switch (Z_TYPE_PP(arg)) {
              case IS_LONG:
              case IS_DOUBLE:
                     RETURN_TRUE;
                     break;

              case IS_STRING:
                     if (is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), NULL, NULL, 0)) {
                            RETURN_TRUE;
                     } else {
                            RETURN_FALSE;
                     }
                     break;

              default:
                     RETURN_FALSE;
                     break;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( is_string  )

Definition at line 277 of file type.c.

Here is the call graph for this function:

PHP_FUNCTION ( is_array  )

Definition at line 285 of file type.c.

Here is the call graph for this function:

PHP_FUNCTION ( is_object  )

Definition at line 293 of file type.c.

Here is the call graph for this function:

PHP_FUNCTION ( is_scalar  )

Definition at line 332 of file type.c.

{
       zval **arg;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) == FAILURE) {
              return;
       }

       switch (Z_TYPE_PP(arg)) {
              case IS_BOOL:
              case IS_DOUBLE:
              case IS_LONG:
              case IS_STRING:
                     RETURN_TRUE;
                     break;

              default:
                     RETURN_FALSE;
                     break;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( is_callable  )

Definition at line 357 of file type.c.

{
       zval *var, **callable_name = NULL;
       char *name;
       char *error;
       zend_bool retval;
       zend_bool syntax_only = 0;
       int check_flags = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|bZ", &var,
                                                   &syntax_only, &callable_name) == FAILURE) {
              return;
       }
       
       if (syntax_only) {
              check_flags |= IS_CALLABLE_CHECK_SYNTAX_ONLY;
       }
       if (ZEND_NUM_ARGS() > 2) {
              retval = zend_is_callable_ex(var, NULL, check_flags, &name, NULL, NULL, &error TSRMLS_CC);
              zval_dtor(*callable_name);
              ZVAL_STRING(*callable_name, name, 0);
       } else {
              retval = zend_is_callable_ex(var, NULL, check_flags, NULL, NULL, NULL, &error TSRMLS_CC);
       }
       if (error) {
              /* ignore errors */
              efree(error);
       }

       RETURN_BOOL(retval);
}

Here is the call graph for this function: