diff --git a/ext/posix/posix.c b/ext/posix/posix.c index b659207f67b6..a65f545e44bd 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -468,7 +468,7 @@ PHP_FUNCTION(posix_ttyname) if (!zend_parse_arg_long(z_fd, &fd, /* is_null */ NULL, /* check_null */ false, /* arg_num */ 1)) { php_error_docref(NULL, E_WARNING, "Argument #1 ($file_descriptor) must be of type int|resource, %s given", zend_zval_value_name(z_fd)); - fd = zval_get_long(z_fd); + RETURN_FALSE; } /* fd must fit in an int and be positive */ if (fd < 0 || fd > INT_MAX) { diff --git a/ext/posix/tests/posix_ttyname_invalid_type_no_fallback.phpt b/ext/posix/tests/posix_ttyname_invalid_type_no_fallback.phpt new file mode 100644 index 000000000000..be881e79604d --- /dev/null +++ b/ext/posix/tests/posix_ttyname_invalid_type_no_fallback.phpt @@ -0,0 +1,24 @@ +--TEST-- +posix_ttyname(): invalid argument type does not fall back to file descriptor 0 +--EXTENSIONS-- +posix +--FILE-- + +--EXPECTF-- +Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be of type int|resource, string given in %s on line %d +bool(false) + +Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be of type int|resource, array given in %s on line %d +bool(false) + +Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be of type int|resource, stdClass given in %s on line %d +bool(false) + +Warning: posix_isatty(): Argument #1 ($file_descriptor) must be of type int|resource, string given in %s on line %d +bool(false) diff --git a/ext/posix/tests/posix_ttyname_manual_zpp.phpt b/ext/posix/tests/posix_ttyname_manual_zpp.phpt index 0fd24efd8f81..271924865c38 100644 --- a/ext/posix/tests/posix_ttyname_manual_zpp.phpt +++ b/ext/posix/tests/posix_ttyname_manual_zpp.phpt @@ -59,12 +59,10 @@ bool(false) class: Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be of type int|resource, stdClass given in %s on line %d -Warning: Object of class stdClass could not be converted to int in %s on line %d bool(false) stringable class: Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be of type int|resource, classWithToString given in %s on line %d -Warning: Object of class classWithToString could not be converted to int in %s on line %d bool(false) int castable class: Warning: posix_ttyname(): Argument #1 ($file_descriptor) must be of type int|resource, GMP given in %s on line %d