To complete Francisco's response , it is valid to place the C source code of the PHP implementation. For example, when using settype
, the documentation recommends:
The possible values for type are:
- "float" (for versions above PHP 4.2.0 only, for old versions use the depreciated variant "double")
That is, you need to set it to float
instead of double
, but checking the implementation of the function, we have:
/* {{{ proto bool settype(mixed &var, string type)
Set the type of the variable */
PHP_FUNCTION(settype)
{
zval *var;
char *type;
size_t type_len = 0;
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_ZVAL_DEREF(var)
Z_PARAM_STRING(type, type_len)
ZEND_PARSE_PARAMETERS_END();
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, E_WARNING, "Cannot convert to resource type");
RETURN_FALSE;
} else {
php_error_docref(NULL, E_WARNING, "Invalid type");
RETURN_FALSE;
}
RETVAL_TRUE;
}
/* }}} */
Where the lines are highlighted:
} else if (!strcasecmp(type, "float")) {
convert_to_double(var);
}
If the type is float
, it converts the value to double
. And the type defined as double
has been rendered obsolete know why (fetch the information in the changelog ).
The same thing happens with the floatval
function:
/* {{{ proto float floatval(mixed var)
Get the float value of a variable */
PHP_FUNCTION(floatval)
{
zval *num;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ZVAL(num)
ZEND_PARSE_PARAMETERS_END();
RETURN_DOUBLE(zval_get_double(num));
}
/* }}} */
Returning the type itself double
.
The complete source file can be seen in the official language repository >.