diff --git a/ext/ftp/ftp.stub.php b/ext/ftp/ftp.stub.php index afcd2064d6e76..17b047399572a 100644 --- a/ext/ftp/ftp.stub.php +++ b/ext/ftp/ftp.stub.php @@ -65,7 +65,7 @@ function ftp_fget($ftp, $fp, string $remote_file, int $mode = FTP_BINARY, int $r * @param resource $ftp * @param resource $fp */ -function ftp_nb_fget($ftp, $fp, string $remote_file, int $mode = FTP_BINARY, int $resumpos = 0): int|false {} +function ftp_nb_fget($ftp, $fp, string $remote_file, int $mode = FTP_BINARY, int $resumpos = 0): int {} /** @param resource $ftp */ function ftp_pasv($ftp, bool $pasv): bool {} @@ -89,7 +89,7 @@ function ftp_fput($ftp, string $remote_file, $fp, int $mode = FTP_BINARY, int $s * @param resource $ftp * @param resource $fp */ -function ftp_nb_fput($ftp, string $remote_file, $fp, int $mode = FTP_BINARY, int $startpos = 0): int|false {} +function ftp_nb_fput($ftp, string $remote_file, $fp, int $mode = FTP_BINARY, int $startpos = 0): int {} /** @param resource $ftp */ function ftp_put($ftp, string $remote_file, string $local_file, int $mode = FTP_BINARY, int $startpos = 0): bool {} diff --git a/ext/ftp/ftp_arginfo.h b/ext/ftp/ftp_arginfo.h index 45cd0e5cf3ad3..b5f160f74c65a 100644 --- a/ext/ftp/ftp_arginfo.h +++ b/ext/ftp/ftp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 830fdf6caf2804d49739fc5112c7091c0f6eb4d4 */ + * Stub hash: 7cf8b5776e7d2ad943683d1f1c43d44b85dea7a1 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_ftp_connect, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, host, IS_STRING, 0) @@ -86,7 +86,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_fget, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, resumepos, IS_LONG, 0, "0") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_nb_fget, 0, 3, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_fget, 0, 3, IS_LONG, 0) ZEND_ARG_INFO(0, ftp) ZEND_ARG_INFO(0, fp) ZEND_ARG_TYPE_INFO(0, remote_file, IS_STRING, 0) @@ -127,7 +127,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_fput, 0, 3, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, startpos, IS_LONG, 0, "0") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ftp_nb_fput, 0, 3, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ftp_nb_fput, 0, 3, IS_LONG, 0) ZEND_ARG_INFO(0, ftp) ZEND_ARG_TYPE_INFO(0, remote_file, IS_STRING, 0) ZEND_ARG_INFO(0, fp) diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c index b27fbef0128c3..0a185ef27294f 100644 --- a/ext/ftp/php_ftp.c +++ b/ext/ftp/php_ftp.c @@ -104,12 +104,12 @@ PHP_MINFO_FUNCTION(ftp) } #define XTYPE(xtype, mode) { \ - if (mode != FTPTYPE_ASCII && mode != FTPTYPE_IMAGE) { \ - php_error_docref(NULL, E_WARNING, "Mode must be FTP_ASCII or FTP_BINARY"); \ - RETURN_FALSE; \ - } \ - xtype = mode; \ - } + if (mode != FTPTYPE_ASCII && mode != FTPTYPE_IMAGE) { \ + zend_argument_value_error(4, "must be either FTP_ASCII or FTP_BINARY"); \ + RETURN_THROWS(); \ + } \ + xtype = mode; \ +} /* {{{ Opens a FTP stream */ @@ -126,8 +126,8 @@ PHP_FUNCTION(ftp_connect) } if (timeout_sec <= 0) { - php_error_docref(NULL, E_WARNING, "Timeout has to be greater than 0"); - RETURN_FALSE; + zend_argument_value_error(3, "must be greater than 0"); + RETURN_THROWS(); } /* connect */ @@ -162,8 +162,8 @@ PHP_FUNCTION(ftp_ssl_connect) } if (timeout_sec <= 0) { - php_error_docref(NULL, E_WARNING, "Timeout has to be greater than 0"); - RETURN_FALSE; + zend_argument_value_error(3, "must be greater than 0"); + RETURN_THROWS(); } /* connect */ @@ -825,7 +825,7 @@ PHP_FUNCTION(ftp_nb_continue) } if (!ftp->nb) { - php_error_docref(NULL, E_WARNING, "No nbronous transfer to continue."); + php_error_docref(NULL, E_WARNING, "No nbronous transfer to continue"); RETURN_LONG(PHP_FTP_FAILED); } @@ -1257,38 +1257,35 @@ PHP_FUNCTION(ftp_set_option) switch (option) { case PHP_FTP_OPT_TIMEOUT_SEC: if (Z_TYPE_P(z_value) != IS_LONG) { - php_error_docref(NULL, E_WARNING, "Option TIMEOUT_SEC expects value of type int, %s given", - zend_zval_type_name(z_value)); - RETURN_FALSE; + zend_argument_type_error(3, "must be of type int for the FTP_TIMEOUT_SEC option, %s given", zend_zval_type_name(z_value)); + RETURN_THROWS(); } if (Z_LVAL_P(z_value) <= 0) { - php_error_docref(NULL, E_WARNING, "Timeout has to be greater than 0"); - RETURN_FALSE; + zend_argument_value_error(3, "must be greater than 0 for the FTP_TIMEOUT_SEC option"); + RETURN_THROWS(); } ftp->timeout_sec = Z_LVAL_P(z_value); RETURN_TRUE; break; case PHP_FTP_OPT_AUTOSEEK: if (Z_TYPE_P(z_value) != IS_TRUE && Z_TYPE_P(z_value) != IS_FALSE) { - php_error_docref(NULL, E_WARNING, "Option AUTOSEEK expects value of type bool, %s given", - zend_zval_type_name(z_value)); - RETURN_FALSE; + zend_argument_type_error(3, "must be of type bool for the FTP_AUTOSEEK option, %s given", zend_zval_type_name(z_value)); + RETURN_THROWS(); } ftp->autoseek = Z_TYPE_P(z_value) == IS_TRUE ? 1 : 0; RETURN_TRUE; break; case PHP_FTP_OPT_USEPASVADDRESS: if (Z_TYPE_P(z_value) != IS_TRUE && Z_TYPE_P(z_value) != IS_FALSE) { - php_error_docref(NULL, E_WARNING, "Option USEPASVADDRESS expects value of type bool, %s given", - zend_zval_type_name(z_value)); - RETURN_FALSE; + zend_argument_type_error(3, "must be of type bool for the FTP_USEPASVADDRESS option, %s given", zend_zval_type_name(z_value)); + RETURN_THROWS(); } ftp->usepasvaddress = Z_TYPE_P(z_value) == IS_TRUE ? 1 : 0; RETURN_TRUE; break; default: - php_error_docref(NULL, E_WARNING, "Unknown option '" ZEND_LONG_FMT "'", option); - RETURN_FALSE; + zend_argument_value_error(2, "must be either FTP_TIMEOUT_SEC, FTP_AUTOSEEK, or FTP_USEPASVADDRESS"); + RETURN_THROWS(); break; } } @@ -1320,9 +1317,8 @@ PHP_FUNCTION(ftp_get_option) RETURN_BOOL(ftp->usepasvaddress); break; default: - php_error_docref(NULL, E_WARNING, "Unknown option '" ZEND_LONG_FMT "'", option); - RETURN_FALSE; - break; + zend_argument_value_error(2, "must be either FTP_TIMEOUT_SEC, FTP_AUTOSEEK, or FTP_USEPASVADDRESS"); + RETURN_THROWS(); } } /* }}} */ diff --git a/ext/ftp/tests/004.phpt b/ext/ftp/tests/004.phpt index b95c12c518d38..e844f024ff350 100644 --- a/ext/ftp/tests/004.phpt +++ b/ext/ftp/tests/004.phpt @@ -9,7 +9,11 @@ require 'skipif.inc'; require 'server.inc'; // Negative timeout -var_dump(ftp_connect('127.0.0.1', 0, -3)); +try { + ftp_connect('127.0.0.1', 0, -3); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} $ftp = ftp_connect('127.0.0.1', $port); if (!$ftp) die("Couldn't connect to the server"); @@ -20,8 +24,7 @@ var_dump(ftp_login($ftp, 'user', 'bogus')); var_dump(ftp_quit($ftp)); ?> --EXPECTF-- -Warning: ftp_connect(): Timeout has to be greater than 0 in %s on line %d -bool(false) +ftp_connect(): Argument #3 ($timeout) must be greater than 0 bool(true) Warning: ftp_login(): Not logged in. in %s on line %d diff --git a/ext/ftp/tests/005.phpt b/ext/ftp/tests/005.phpt index 4b46321e26bde..c1c749d08cdab 100644 --- a/ext/ftp/tests/005.phpt +++ b/ext/ftp/tests/005.phpt @@ -20,14 +20,40 @@ var_dump(ftp_chdir($ftp, '~')); var_dump(ftp_chmod($ftp, 0666, 'x')); var_dump(ftp_delete($ftp, 'x')); var_dump(ftp_exec($ftp, 'x')); -var_dump(ftp_fget($ftp, STDOUT, 'x', 0)); -var_dump(ftp_fput($ftp, 'x', fopen(__FILE__, 'r'), 0)); -var_dump(ftp_get($ftp, 'x', 'y', 0)); +try { + ftp_fget($ftp, STDOUT, 'x', 0); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + ftp_fput($ftp, 'x', fopen(__FILE__, 'r'), 0); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + ftp_get($ftp, 'x', 'y', 0); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(ftp_mdtm($ftp, 'x')); var_dump(ftp_mkdir($ftp, 'x')); var_dump(ftp_nb_continue($ftp)); -var_dump(ftp_nb_fget($ftp, STDOUT, 'x', 0)); -var_dump(ftp_nb_fput($ftp, 'x', fopen(__FILE__, 'r'), 0)); + +try { + ftp_nb_fget($ftp, STDOUT, 'x', 0); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + ftp_nb_fput($ftp, 'x', fopen(__FILE__, 'r'), 0); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + var_dump(ftp_systype($ftp)); var_dump(ftp_pwd($ftp)); var_dump(ftp_size($ftp, '')); @@ -38,49 +64,39 @@ var_dump(ftp_rmdir($ftp, '')); bool(true) bool(false) -Warning: ftp_cdup(): Command not implemented (1). in %s005.php on line 11 -bool(false) - -Warning: ftp_chdir(): Command not implemented (2). in %s005.php on line 12 -bool(false) - -Warning: ftp_chmod(): Command not implemented (3). in %s005.php on line 13 -bool(false) - -Warning: ftp_delete(): Command not implemented (4). in %s005.php on line 14 +Warning: ftp_cdup(): Command not implemented (1). in %s005.php on line %d bool(false) -Warning: ftp_exec(): Command not implemented (5). in %s005.php on line 15 +Warning: ftp_chdir(): Command not implemented (2). in %s005.php on line %d bool(false) -Warning: ftp_fget(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 16 +Warning: ftp_chmod(): Command not implemented (3). in %s005.php on line %d bool(false) -Warning: ftp_fput(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 17 +Warning: ftp_delete(): Command not implemented (4). in %s005.php on line %d bool(false) -Warning: ftp_get(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 18 +Warning: ftp_exec(): Command not implemented (5). in %s005.php on line %d bool(false) +ftp_fget(): Argument #4 ($mode) must be either FTP_ASCII or FTP_BINARY +ftp_fput(): Argument #4 ($mode) must be either FTP_ASCII or FTP_BINARY +ftp_get(): Argument #4 ($mode) must be either FTP_ASCII or FTP_BINARY int(-1) -Warning: ftp_mkdir(): Command not implemented (7). in %s005.php on line 20 +Warning: ftp_mkdir(): Command not implemented (7). in %s005.php on line %d bool(false) -Warning: ftp_nb_continue(): No nbronous transfer to continue. in %s005.php on line 21 +Warning: ftp_nb_continue(): No nbronous transfer to continue in %s005.php on line %d int(0) +ftp_nb_fget(): Argument #4 ($mode) must be either FTP_ASCII or FTP_BINARY +ftp_nb_fput(): Argument #4 ($mode) must be either FTP_ASCII or FTP_BINARY -Warning: ftp_nb_fget(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 22 -bool(false) - -Warning: ftp_nb_fput(): Mode must be FTP_ASCII or FTP_BINARY in %s005.php on line 23 -bool(false) - -Warning: ftp_systype(): Command not implemented (8). in %s005.php on line 24 +Warning: ftp_systype(): Command not implemented (8). in %s005.php on line %d bool(false) -Warning: ftp_pwd(): Command not implemented (9). in %s005.php on line 25 +Warning: ftp_pwd(): Command not implemented (9). in %s005.php on line %d bool(false) int(-1) -Warning: ftp_rmdir(): Command not implemented (11). in %s005.php on line 27 +Warning: ftp_rmdir(): Command not implemented (11). in %s005.php on line %d bool(false) diff --git a/ext/ftp/tests/ftp_get_option.phpt b/ext/ftp/tests/ftp_get_option.phpt index 06b34fc72051a..336243d64ba75 100644 --- a/ext/ftp/tests/ftp_get_option.phpt +++ b/ext/ftp/tests/ftp_get_option.phpt @@ -16,12 +16,16 @@ $ftp or die("Couldn't connect to the server"); var_dump(ftp_get_option($ftp, FTP_TIMEOUT_SEC)); var_dump(ftp_get_option($ftp, FTP_AUTOSEEK)); var_dump(ftp_get_option($ftp, FTP_USEPASVADDRESS)); -var_dump(ftp_get_option($ftp, FOO_BAR)); + +try { + ftp_get_option($ftp, FOO_BAR); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + ?> --EXPECTF-- int(%d) bool(true) bool(true) - -Warning: ftp_get_option(): Unknown option '10' in %s on line %d -bool(false) +ftp_get_option(): Argument #2 ($option) must be either FTP_TIMEOUT_SEC, FTP_AUTOSEEK, or FTP_USEPASVADDRESS diff --git a/ext/ftp/tests/ftp_set_option_errors.phpt b/ext/ftp/tests/ftp_set_option_errors.phpt index ad91be56e8a66..03c387975e0b9 100644 --- a/ext/ftp/tests/ftp_set_option_errors.phpt +++ b/ext/ftp/tests/ftp_set_option_errors.phpt @@ -13,24 +13,40 @@ $ftp = ftp_connect('127.0.0.1', $port); ftp_login($ftp, 'user', 'pass'); $ftp or die("Couldn't connect to the server"); -var_dump(ftp_set_option($ftp, FTP_TIMEOUT_SEC, 0)); -var_dump(ftp_set_option($ftp, FTP_TIMEOUT_SEC, '0')); -var_dump(ftp_set_option($ftp, FTP_USEPASVADDRESS, ['1'])); -var_dump(ftp_set_option($ftp, FTP_AUTOSEEK, 'true')); -var_dump(ftp_set_option($ftp, FOO_BAR, 1)); -?> ---EXPECTF-- -Warning: ftp_set_option(): Timeout has to be greater than 0 in %s on line %d -bool(false) +try { + ftp_set_option($ftp, FTP_TIMEOUT_SEC, 0); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + ftp_set_option($ftp, FTP_TIMEOUT_SEC, '0'); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: ftp_set_option(): Option TIMEOUT_SEC expects value of type int, string given in %s on line %d -bool(false) +try { + ftp_set_option($ftp, FTP_USEPASVADDRESS, ['1']); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: ftp_set_option(): Option USEPASVADDRESS expects value of type bool, array given in %s on line %d -bool(false) +try { + ftp_set_option($ftp, FTP_AUTOSEEK, 'true'); +} catch (TypeError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: ftp_set_option(): Option AUTOSEEK expects value of type bool, string given in %s on line %d -bool(false) +try { + ftp_set_option($ftp, FOO_BAR, 1); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} -Warning: ftp_set_option(): Unknown option '10' in %s on line %d -bool(false) +?> +--EXPECT-- +ftp_set_option(): Argument #3 ($value) must be greater than 0 for the FTP_TIMEOUT_SEC option +ftp_set_option(): Argument #3 ($value) must be of type int for the FTP_TIMEOUT_SEC option, string given +ftp_set_option(): Argument #3 ($value) must be of type bool for the FTP_USEPASVADDRESS option, array given +ftp_set_option(): Argument #3 ($value) must be of type bool for the FTP_AUTOSEEK option, string given +ftp_set_option(): Argument #2 ($option) must be either FTP_TIMEOUT_SEC, FTP_AUTOSEEK, or FTP_USEPASVADDRESS diff --git a/ext/ftp/tests/ftp_ssl_connect_error.phpt b/ext/ftp/tests/ftp_ssl_connect_error.phpt index 13c8f9e9c02cb..61646293faac5 100644 --- a/ext/ftp/tests/ftp_ssl_connect_error.phpt +++ b/ext/ftp/tests/ftp_ssl_connect_error.phpt @@ -12,8 +12,12 @@ echo "*** Testing ftp_ssl_connect() function : error conditions ***\n"; echo "\n-- Testing ftp_ssl_connect() function on failure --\n"; var_dump(ftp_ssl_connect('totes.invalid')); -echo "\n-- Testing ftp_ssl_connect() function timeout warning for value 0 --\n"; -ftp_ssl_connect('totes.invalid', 21, 0); +echo "\n-- Testing ftp_ssl_connect() function timeout exception for value 0 --\n"; +try { + ftp_ssl_connect('totes.invalid', 21, 0); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} echo "===DONE===\n"; --EXPECTF-- @@ -24,7 +28,6 @@ echo "===DONE===\n"; Warning: ftp_ssl_connect(): php_network_getaddresses: getaddrinfo failed: %s in %s on line %d bool(false) --- Testing ftp_ssl_connect() function timeout warning for value 0 -- - -Warning: ftp_ssl_connect(): Timeout has to be greater than 0 in %s on line %d +-- Testing ftp_ssl_connect() function timeout exception for value 0 -- +ftp_ssl_connect(): Argument #3 ($timeout) must be greater than 0 ===DONE===