--- /dev/null
+--TEST--
+Float type hint should not allow invalid types as default
+--FILE--
+<?php
+
+function test(float $arg = true)
+{
+ var_dump($arg);
+}
+
+test();
+
+?>
+--EXPECTF--
+
+Fatal error: Default value for parameters with a float type hint can only be float, integer, or NULL in %s on line %d
if (arg_info->class_name) {
zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
"with a class type hint can only be NULL");
- } else if (!ZEND_SAME_FAKE_TYPE(arg_info->type_hint, Z_TYPE(default_node.u.constant))) {
- zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
- "with a %s type hint can only be %s or NULL",
- zend_get_type_by_const(arg_info->type_hint), zend_get_type_by_const(arg_info->type_hint));
+ } else switch (arg_info->type_hint) {
+ case IS_DOUBLE:
+ if (Z_TYPE(default_node.u.constant) != IS_DOUBLE && Z_TYPE(default_node.u.constant) != IS_LONG) {
+ zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
+ "with a float type hint can only be float, integer, or NULL");
+ }
+ break;
+
+ default:
+ if (!ZEND_SAME_FAKE_TYPE(arg_info->type_hint, Z_TYPE(default_node.u.constant))) {
+ zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
+ "with a %s type hint can only be %s or NULL",
+ zend_get_type_by_const(arg_info->type_hint), zend_get_type_by_const(arg_info->type_hint));
+ }
+ break;
}
}
}