Пример #1
0
static inline void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type)
{
	zval *arg;

#ifndef FAST_ZPP
	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &arg) == FAILURE) {
		RETURN_FALSE;
	}
	ZVAL_DEREF(arg);
#else
	ZEND_PARSE_PARAMETERS_START(1, 1)
		Z_PARAM_ZVAL_DEREF(arg)
	ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
#endif

	if (Z_TYPE_P(arg) == type) {
		if (type == IS_OBJECT) {
			zend_class_entry *ce = Z_OBJCE_P(arg);
			if (ce->name->len == sizeof(INCOMPLETE_CLASS) - 1
					&& !memcmp(ce->name->val, INCOMPLETE_CLASS, sizeof(INCOMPLETE_CLASS) - 1)) {
				RETURN_FALSE;
			}
		} else if (type == IS_RESOURCE) {
			const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(arg));
			if (!type_name) {
				RETURN_FALSE;
			}
		}
		RETURN_TRUE;
	} else {
		RETURN_FALSE;
	}
}
Пример #2
0
static void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type)
{
	pval **arg;

	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only one argument expected");
		RETURN_FALSE;
	}

	if (Z_TYPE_PP(arg) == type) {
		if (type == IS_OBJECT) {
			zend_class_entry *ce;
			ce = Z_OBJCE_PP(arg);
			if (!strcmp(ce->name, INCOMPLETE_CLASS)) {
				RETURN_FALSE;
			}
		}
		if (type == IS_RESOURCE) {
			char *type_name;
			type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(arg) TSRMLS_CC);
			if (!type_name) {
				RETURN_FALSE;
			}
		}
		RETURN_TRUE;
	} else {
		RETURN_FALSE;
	}
}
Пример #3
0
static void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type)
{
	zval **arg;

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

	if (Z_TYPE_PP(arg) == type) {
		if (type == IS_OBJECT) {
			zend_class_entry *ce;
			if(Z_OBJ_HT_PP(arg)->get_class_entry == NULL) {
			/* if there's no get_class_entry it's not a PHP object, so it can't be INCOMPLETE_CLASS */
				RETURN_TRUE;
			}
			ce = Z_OBJCE_PP(arg);
			if (!strcmp(ce->name, INCOMPLETE_CLASS)) {
				RETURN_FALSE;
			}
		}
		if (type == IS_RESOURCE) {
			const char *type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(arg) TSRMLS_CC);
			if (!type_name) {
				RETURN_FALSE;
			}
		}
		RETURN_TRUE;
	} else {
		RETURN_FALSE;
	}
}
Пример #4
0
static const char* _symfony_debug_get_resource_type(long rsid TSRMLS_DC)
{
	const char *res_type;
	res_type = zend_rsrc_list_get_rsrc_type(rsid TSRMLS_CC);

	if (!res_type) {
		return "Unknown";
	}

	return res_type;
}
Пример #5
0
/**
 * Returns the type of a variable as a string
 */
void zephir_gettype(zval *return_value, zval *arg)
{
	switch (Z_TYPE_P(arg)) {

		case IS_NULL:
			RETVAL_STRING("NULL");
			break;

		case IS_TRUE:
		case IS_FALSE:
			RETVAL_STRING("boolean");
			break;

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

		case IS_DOUBLE:
			RETVAL_STRING("double");
			break;

		case IS_STRING:
			RETVAL_STRING("string");
			break;

		case IS_ARRAY:
			RETVAL_STRING("array");
			break;

		case IS_OBJECT:
			RETVAL_STRING("object");
			break;

		case IS_RESOURCE:
			{
				const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(arg));

				if (type_name) {
					RETVAL_STRING("resource");
					break;
				}
			}

		default:
			RETVAL_STRING("unknown type");
	}
}
Пример #6
0
static PHP_FUNCTION(params_dump) {
    zval *arg;//定义参数值,zval可以表示所有的参数的值

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

    switch(Z_TYPE_P(arg)) {
        case IS_NULL://arg is null
            php_printf("NULL\n");
            break;
        case IS_BOOL://arg is true, false
            php_printf("bool(%s)\n", Z_BVAL_P(arg)?"true":"false");
            break;
        case IS_LONG:
            php_printf("int(%d)\n", Z_LVAL_P(arg));
            break;
        case IS_DOUBLE:
            php_printf("float(%f)\n", Z_DVAL_P(arg));
            break;
        case IS_STRING:
            php_printf("string(%d)\n", Z_STRLEN_P(arg));
            PHPWRITE(Z_STRVAL_P(arg), Z_STRLEN_P(arg));
            php_printf("\n");
            break;
        case IS_ARRAY:
            php_printf("array(%d){...}\n", zend_hash_num_elements(Z_ARRVAL_P(arg)));
            break;
        case IS_RESOURCE:{
            const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RESVAL_P(arg) TSRMLS_CC);
            php_printf("resource#%ld(%s)\n", Z_RESVAL_P(arg), type_name?type_name:"Unknown");
            break;
        }
        case IS_OBJECT:{
            const zend_class_entry *ce = Z_OBJCE_P(arg);
            php_printf("object#%u(%s)\n", Z_OBJ_HANDLE_P(arg), (ce && ce->name)?ce->name:"Unknown");
            break;
        }
        default:
            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown type: %d\n", Z_TYPE_P(arg));
    }

}
Пример #7
0
static inline void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type)
{
	zval *arg;

	ZEND_PARSE_PARAMETERS_START(1, 1)
		Z_PARAM_ZVAL(arg)
	ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

	if (Z_TYPE_P(arg) == type) {
		if (type == IS_RESOURCE) {
			const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(arg));
			if (!type_name) {
				RETURN_FALSE;
			}
		}
		RETURN_TRUE;
	} else {
		RETURN_FALSE;
	}
}
Пример #8
0
static inline void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type)
{
	zval *arg;

#ifndef FAST_ZPP
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) {
		RETURN_FALSE;
	}
	ZVAL_DEREF(arg);
#else
	ZEND_PARSE_PARAMETERS_START(1, 1)
		Z_PARAM_ZVAL_DEREF(arg)
	ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
#endif

	if (Z_TYPE_P(arg) == type) {
		if (type == IS_OBJECT) {
			zend_class_entry *ce;
			if (Z_OBJ_HT_P(arg)->get_class_entry == NULL) {
				/* if there's no get_class_entry it's not a PHP object, so it can't be INCOMPLETE_CLASS */
				RETURN_TRUE;
			}
			ce = Z_OBJCE_P(arg);
			if (ce->name->len == sizeof(INCOMPLETE_CLASS) - 1 
					&& !strncmp(ce->name->val, INCOMPLETE_CLASS, ce->name->len)) {
				RETURN_FALSE;
			}
		} else if (type == IS_RESOURCE) {
			const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(arg) TSRMLS_CC);
			if (!type_name) {
				RETURN_FALSE;
			}
		}
		RETURN_TRUE;
	} else {
		RETURN_FALSE;
	}
}