}
/* }}} */
+ZEND_API int ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest) /* {{{ */
+{
+ if (UNEXPECTED(ZEND_ARG_USES_STRICT_TYPES())) {
+ return 0;
+ }
+ if (Z_TYPE_P(arg) == IS_STRING) {
+ zend_string *str = Z_STR_P(arg);
+ zend_long lval;
+ double dval;
+ zend_uchar type = is_numeric_string(ZSTR_VAL(str), ZSTR_LEN(str), &lval, &dval, -1);
+ if (type == IS_LONG) {
+ ZVAL_LONG(arg, lval);
+ } else if (type == IS_DOUBLE) {
+ ZVAL_DOUBLE(arg, dval);
+ } else {
+ return 0;
+ }
+ zend_string_release(str);
+ } else if (Z_TYPE_P(arg) < IS_TRUE) {
+ ZVAL_LONG(arg, 0);
+ } else if (Z_TYPE_P(arg) == IS_TRUE) {
+ ZVAL_LONG(arg, 1);
+ } else {
+ return 0;
+ }
+ *dest = arg;
+ return 1;
+}
+/* }}} */
+
ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest) /* {{{ */
{
if (EXPECTED(Z_TYPE_P(arg) < IS_STRING)) {
_(Z_EXPECTED_RESOURCE, "resource") \
_(Z_EXPECTED_PATH, "a valid path") \
_(Z_EXPECTED_OBJECT, "object") \
- _(Z_EXPECTED_DOUBLE, "float")
+ _(Z_EXPECTED_DOUBLE, "float") \
+ _(Z_EXPECTED_NUMBER, "int or float") \
#define Z_EXPECTED_TYPE_ENUM(id, str) id,
#define Z_EXPECTED_TYPE_STR(id, str) str,
#define Z_PARAM_LONG(dest) \
Z_PARAM_LONG_EX(dest, _dummy, 0, 0)
+
+/* no old equivalent */
+#define Z_PARAM_NUMBER_EX(dest, check_null) \
+ Z_PARAM_PROLOGUE(0, 0); \
+ if (UNEXPECTED(!zend_parse_arg_number(_arg, &dest, check_null))) { \
+ _expected_type = Z_EXPECTED_NUMBER; \
+ _error_code = ZPP_ERROR_WRONG_ARG; \
+ break; \
+ }
+
+#define Z_PARAM_NUMBER_OR_NULL(dest) \
+ Z_PARAM_NUMBER_EX(dest, 1)
+
+#define Z_PARAM_NUMBER(dest) \
+ Z_PARAM_NUMBER_EX(dest, 0)
+
/* old "o" */
#define Z_PARAM_OBJECT_EX2(dest, check_null, deref, separate) \
Z_PARAM_PROLOGUE(deref, separate); \
ZEND_API int ZEND_FASTCALL zend_parse_arg_double_weak(zval *arg, double *dest);
ZEND_API int ZEND_FASTCALL zend_parse_arg_str_slow(zval *arg, zend_string **dest);
ZEND_API int ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **dest);
+ZEND_API int ZEND_FASTCALL zend_parse_arg_number_slow(zval *arg, zval **dest);
static zend_always_inline int zend_parse_arg_bool(zval *arg, zend_bool *dest, zend_bool *is_null, int check_null)
{
return 1;
}
+static zend_always_inline int zend_parse_arg_number(zval *arg, zval **dest, int check_null)
+{
+ if (EXPECTED(Z_TYPE_P(arg) == IS_LONG || Z_TYPE_P(arg) == IS_DOUBLE)) {
+ *dest = arg;
+ } else if (check_null && EXPECTED(Z_TYPE_P(arg) == IS_NULL)) {
+ *dest = NULL;
+ } else {
+ return zend_parse_arg_number_slow(arg, dest);
+ }
+ return 1;
+}
+
static zend_always_inline int zend_parse_arg_str(zval *arg, zend_string **dest, int check_null)
{
if (EXPECTED(Z_TYPE_P(arg) == IS_STRING)) {
F0("password_verify", MAY_BE_FALSE | MAY_BE_TRUE),
F1("convert_uuencode", MAY_BE_FALSE | MAY_BE_STRING),
F1("convert_uudecode", MAY_BE_FALSE | MAY_BE_STRING),
- F0("abs", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_DOUBLE),
- F0("ceil", MAY_BE_FALSE | MAY_BE_DOUBLE),
- F0("floor", MAY_BE_FALSE | MAY_BE_DOUBLE),
+ F0("abs", MAY_BE_LONG | MAY_BE_DOUBLE),
+ F0("ceil", MAY_BE_DOUBLE),
+ F0("floor", MAY_BE_DOUBLE),
F0("round", MAY_BE_FALSE | MAY_BE_DOUBLE),
F0("sin", MAY_BE_DOUBLE),
F0("cos", MAY_BE_DOUBLE),
Z_PARAM_ZVAL(zlow)
Z_PARAM_ZVAL(zhigh)
Z_PARAM_OPTIONAL
- Z_PARAM_ZVAL(zstep)
- ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
+ Z_PARAM_NUMBER(zstep)
+ ZEND_PARSE_PARAMETERS_END();
if (zstep) {
- if (Z_TYPE_P(zstep) == IS_DOUBLE) {
- is_step_double = 1;
- } else if (Z_TYPE_P(zstep) == IS_STRING) {
- int type = is_numeric_string(Z_STRVAL_P(zstep), Z_STRLEN_P(zstep), NULL, NULL, 0);
- if (type == IS_DOUBLE) {
- is_step_double = 1;
- }
- if (type == 0) {
- /* bad number */
- php_error_docref(NULL, E_WARNING, "Invalid range string - must be numeric");
- RETURN_FALSE;
- }
- }
-
+ is_step_double = Z_TYPE_P(zstep) == IS_DOUBLE;
step = zval_get_double(zstep);
/* We only want positive step values. */
}
/* }}}*/
-/* {{{ proto int|float|false abs(int number)
+/* {{{ proto int|float abs(int number)
Return the absolute value of the number */
PHP_FUNCTION(abs)
{
zval *value;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(value)
+ Z_PARAM_NUMBER(value)
ZEND_PARSE_PARAMETERS_END();
- convert_scalar_to_number_ex(value);
-
if (Z_TYPE_P(value) == IS_DOUBLE) {
RETURN_DOUBLE(fabs(Z_DVAL_P(value)));
} else if (Z_TYPE_P(value) == IS_LONG) {
} else {
RETURN_LONG(Z_LVAL_P(value) < 0 ? -Z_LVAL_P(value) : Z_LVAL_P(value));
}
+ } else {
+ ZEND_ASSERT(0 && "Unexpected type");
}
- RETURN_FALSE;
}
/* }}} */
-/* {{{ proto float|false ceil(float number)
+/* {{{ proto float ceil(float number)
Returns the next highest integer value of the number */
PHP_FUNCTION(ceil)
{
zval *value;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(value)
+ Z_PARAM_NUMBER(value)
ZEND_PARSE_PARAMETERS_END();
- convert_scalar_to_number_ex(value);
-
if (Z_TYPE_P(value) == IS_DOUBLE) {
RETURN_DOUBLE(ceil(Z_DVAL_P(value)));
} else if (Z_TYPE_P(value) == IS_LONG) {
RETURN_DOUBLE(zval_get_double(value));
+ } else {
+ ZEND_ASSERT(0 && "Unexpected type");
}
- RETURN_FALSE;
}
/* }}} */
-/* {{{ proto float|false floor(float number)
+/* {{{ proto float floor(float number)
Returns the next lowest integer value from the number */
PHP_FUNCTION(floor)
{
zval *value;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(value)
+ Z_PARAM_NUMBER(value)
ZEND_PARSE_PARAMETERS_END();
- convert_scalar_to_number_ex(value);
-
if (Z_TYPE_P(value) == IS_DOUBLE) {
RETURN_DOUBLE(floor(Z_DVAL_P(value)));
} else if (Z_TYPE_P(value) == IS_LONG) {
RETURN_DOUBLE(zval_get_double(value));
+ } else {
+ ZEND_ASSERT(0 && "Unexpected type");
}
- RETURN_FALSE;
}
/* }}} */
echo "\n-- Testing other conditions --";
var_dump( range(-1, -2, 2) );
-var_dump( range("a", "j", "z") );
+try {
+ var_dump( range("a", "j", "z") );
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
var_dump( range(0, 1, "140962482048819216326.24") );
var_dump( range(0, 1, "140962482048819216326.24.") );
$step_arr = array( "string", NULL, FALSE, "", "\0" );
foreach( $step_arr as $step ) {
- var_dump( range( 1, 5, $step ) );
+ try {
+ var_dump( range( 1, 5, $step ) );
+ } catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+ }
}
echo "Done\n";
-- Testing other conditions --
Warning: range(): step exceeds the specified range in %s on line %d
bool(false)
-
-Warning: range(): Invalid range string - must be numeric in %s on line %d
-bool(false)
+range() expects parameter 3 to be int or float, string given
Warning: range(): step exceeds the specified range in %s on line %d
bool(false)
-Warning: range(): Invalid range string - must be numeric in %s on line %d
-bool(false)
-
--- Testing Invalid steps --
-Warning: range(): Invalid range string - must be numeric in %s on line %d
-bool(false)
+Notice: A non well formed numeric value encountered in %s on line %d
Warning: range(): step exceeds the specified range in %s on line %d
bool(false)
-Warning: range(): step exceeds the specified range in %s on line %d
-bool(false)
+-- Testing Invalid steps --range() expects parameter 3 to be int or float, string given
-Warning: range(): Invalid range string - must be numeric in %s on line %d
+Warning: range(): step exceeds the specified range in %s on line %d
bool(false)
-Warning: range(): Invalid range string - must be numeric in %s on line %d
+Warning: range(): step exceeds the specified range in %s on line %d
bool(false)
+range() expects parameter 3 to be int or float, string given
+range() expects parameter 3 to be int or float, string given
Done
echo "\n*** Possible variatins with steps ***\n";
var_dump( range( 1, 5, TRUE ) );
-var_dump( range( 1, 5, array(1, 2) ) );
+try {
+ var_dump( range( 1, 5, array(1, 2) ) );
+} catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+}
echo "Done\n";
?>
[4]=>
int(5)
}
-array(5) {
- [0]=>
- int(1)
- [1]=>
- int(2)
- [2]=>
- int(3)
- [3]=>
- int(4)
- [4]=>
- int(5)
-}
+range() expects parameter 3 to be int or float, array given
Done
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
- var_dump(abs($input) );
+ try {
+ var_dump(abs($input));
+ } catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+ }
$iterator++;
};
fclose($fp);
?>
===Done===
---EXPECTF--
+--EXPECT--
*** Testing abs() : usage variations ***
-- Iteration 1 --
int(0)
-- Iteration 7 --
-int(0)
+abs() expects parameter 1 to be int or float, string given
-- Iteration 8 --
-int(0)
+abs() expects parameter 1 to be int or float, string given
-- Iteration 9 --
-bool(false)
+abs() expects parameter 1 to be int or float, array given
-- Iteration 10 --
-int(0)
+abs() expects parameter 1 to be int or float, string given
-- Iteration 11 --
-int(0)
+abs() expects parameter 1 to be int or float, string given
-- Iteration 12 --
-int(0)
+abs() expects parameter 1 to be int or float, string given
-- Iteration 13 --
-
-Notice: Object of class classA could not be converted to number in %s on line %d
-int(1)
+abs() expects parameter 1 to be int or float, object given
-- Iteration 14 --
int(0)
int(0)
-- Iteration 16 --
-int(%d)
+abs() expects parameter 1 to be int or float, resource given
===Done===
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
- var_dump(ceil($input));
+ try {
+ var_dump(ceil($input));
+ } catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+ }
$iterator++;
};
fclose($fp);
?>
===Done===
---EXPECTF--
+--EXPECT--
*** Testing ceil() : usage variations ***
-- Iteration 1 --
float(0)
-- Iteration 7 --
-float(0)
+ceil() expects parameter 1 to be int or float, string given
-- Iteration 8 --
-float(0)
+ceil() expects parameter 1 to be int or float, string given
-- Iteration 9 --
-bool(false)
+ceil() expects parameter 1 to be int or float, array given
-- Iteration 10 --
-float(0)
+ceil() expects parameter 1 to be int or float, string given
-- Iteration 11 --
-float(0)
+ceil() expects parameter 1 to be int or float, string given
-- Iteration 12 --
-float(0)
+ceil() expects parameter 1 to be int or float, string given
-- Iteration 13 --
-
-Notice: Object of class classA could not be converted to number in %s on line %d
-float(1)
+ceil() expects parameter 1 to be int or float, object given
-- Iteration 14 --
float(0)
float(0)
-- Iteration 16 --
-float(%d)
+ceil() expects parameter 1 to be int or float, resource given
===Done===
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
- var_dump(floor($input));
+ try {
+ var_dump(floor($input));
+ } catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+ }
$iterator++;
};
fclose($fp);
?>
===Done===
---EXPECTF--
+--EXPECT--
*** Testing floor() : usage variations ***
-- Iteration 1 --
float(0)
-- Iteration 7 --
-float(0)
+floor() expects parameter 1 to be int or float, string given
-- Iteration 8 --
-float(0)
+floor() expects parameter 1 to be int or float, string given
-- Iteration 9 --
-bool(false)
+floor() expects parameter 1 to be int or float, array given
-- Iteration 10 --
-float(0)
+floor() expects parameter 1 to be int or float, string given
-- Iteration 11 --
-float(0)
+floor() expects parameter 1 to be int or float, string given
-- Iteration 12 --
-float(0)
+floor() expects parameter 1 to be int or float, string given
-- Iteration 13 --
-
-Notice: Object of class classA could not be converted to number in %s on line %d
-float(1)
+floor() expects parameter 1 to be int or float, object given
-- Iteration 14 --
float(0)
float(0)
-- Iteration 16 --
-float(%f)
+floor() expects parameter 1 to be int or float, resource given
===Done===