Skip to content

Promote warnings to exceptions in the standard lib #4937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
441b326
Promote warning to exception in log() function
kocsismate Nov 20, 2019
ee3b345
Promote warning to exception in ini_get_all() function
kocsismate Nov 20, 2019
e5a8bae
Promote warning to exception in parse_ini_file() function
kocsismate Nov 20, 2019
c30e234
Promote warnings to exceptions in dl() function
kocsismate Nov 20, 2019
9b4cf61
Promote warnings to exceptions in password_*() functions
kocsismate Nov 20, 2019
7adf0ce
Promote warning to exception in get_browser() function
kocsismate Nov 20, 2019
b550ea3
Promote warning to exception in dns_check_record() function
kocsismate Nov 20, 2019
716c677
Promote warning to exception in convert_uudecode() function
kocsismate Nov 20, 2019
d2d9f6f
Promote warnings to exceptions in settype() function
kocsismate Nov 20, 2019
2895a86
Promote warrnings to exceptions in chgrp() function
kocsismate Nov 20, 2019
174cb29
Promote warning to exception in constant() function
kocsismate Nov 20, 2019
1833afc
Promote warning to exception in file_get_contents() function
kocsismate Nov 20, 2019
b87ecf3
Promote warnings to exceptions in proc_open() function
kocsismate Nov 20, 2019
b610f2e
Capitalize the initial letter of the error message of htmlspecialchar…
kocsismate Nov 20, 2019
b2b219c
Promote warning to exception in the levenshtein() function
kocsismate Nov 20, 2019
474bbc6
Promote warnings to exceptions in some URL and file related functions
kocsismate Nov 20, 2019
bc6bb44
Promote warnings to exceptions in string search related functions
kocsismate Nov 20, 2019
49b87c0
Promote warnings to exceptions in *scanf() functions
kocsismate Nov 20, 2019
5025c88
Promote warning to exception in the convert_uudecode() function
kocsismate Nov 20, 2019
023f629
Promote warnings to exceptions in register_shutdown_handler() function
kocsismate Nov 20, 2019
ddd8362
Promote warnings to exceptions in register_tick_function() function
kocsismate Nov 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/opcache/Optimizer/zend_func_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ static const func_info_t func_infos[] = {
F0("log1p", MAY_BE_DOUBLE),
F1("pow", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_DOUBLE | MAY_BE_OBJECT),
F0("exp", MAY_BE_DOUBLE),
F0("log", MAY_BE_FALSE | MAY_BE_DOUBLE),
F0("log", MAY_BE_DOUBLE),
F0("log10", MAY_BE_DOUBLE),
F0("sqrt", MAY_BE_DOUBLE),
F0("hypot", MAY_BE_DOUBLE),
Expand Down Expand Up @@ -363,7 +363,7 @@ static const func_info_t func_infos[] = {
F1("highlight_string", MAY_BE_FALSE | MAY_BE_TRUE | MAY_BE_STRING),
F1("php_strip_whitespace", MAY_BE_STRING),
FN("ini_get", MAY_BE_FALSE | MAY_BE_STRING),
F1("ini_get_all", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
F1("ini_get_all", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_NULL | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
FN("ini_set", MAY_BE_FALSE | MAY_BE_STRING),
F1("ini_alter", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING),
F0("ini_restore", MAY_BE_NULL),
Expand Down
11 changes: 5 additions & 6 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3556,7 +3556,7 @@ PHP_FUNCTION(ini_get)
}
/* }}} */

/* {{{ proto array|false ini_get_all([string extension[, bool details = true]])
/* {{{ proto array ini_get_all([string extension[, bool details = true]])
Get all configuration options */
PHP_FUNCTION(ini_get_all)
{
Expand All @@ -3567,7 +3567,6 @@ PHP_FUNCTION(ini_get_all)
zend_string *key;
zend_ini_entry *ini_entry;


ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(extname, extname_len)
Expand All @@ -3578,8 +3577,8 @@ PHP_FUNCTION(ini_get_all)

if (extname) {
if ((module = zend_hash_str_find_ptr(&module_registry, extname, extname_len)) == NULL) {
php_error_docref(NULL, E_WARNING, "Unable to find extension '%s'", extname);
RETURN_FALSE;
zend_value_error("Unable to find extension '%s'", extname);
return;
}
module_number = module->module_number;
}
Expand Down Expand Up @@ -4215,8 +4214,8 @@ PHP_FUNCTION(parse_ini_file)
ZEND_PARSE_PARAMETERS_END();

if (filename_len == 0) {
php_error_docref(NULL, E_WARNING, "Filename cannot be empty!");
RETURN_FALSE;
zend_value_error("Filename cannot be empty!");
return;
}

/* Set callback function */
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function highlight_string(string $string, bool $return = false): string|bool|nul

function ini_get(string $varname): string|false {}

function ini_get_all(?string $extension = null, bool $details = true): array|false {}
function ini_get_all(?string $extension = null, bool $details = true): array {}

function ini_set(string $varname, string $value): string|false {}

Expand Down Expand Up @@ -911,7 +911,7 @@ function pow($base, $exp) {}

function exp(float $number): float {}

function log(float $number, float $base = M_E): float|false {}
function log(float $number, float $base = M_E): float {}

function log10(float $number): float {}

Expand Down
4 changes: 2 additions & 2 deletions ext/standard/basic_functions_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ini_get, 0, 1, MAY_BE_STRING|MAY
ZEND_ARG_TYPE_INFO(0, varname, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ini_get_all, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ini_get_all, 0, 0, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, extension, IS_STRING, 1)
ZEND_ARG_TYPE_INFO(0, details, _IS_BOOL, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -1386,7 +1386,7 @@ ZEND_END_ARG_INFO()

#define arginfo_exp arginfo_ceil

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_log, 0, 1, MAY_BE_DOUBLE|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_log, 0, 1, IS_DOUBLE, 0)
ZEND_ARG_TYPE_INFO(0, number, IS_DOUBLE, 0)
ZEND_ARG_TYPE_INFO(0, base, IS_DOUBLE, 0)
ZEND_END_ARG_INFO()
Expand Down
6 changes: 3 additions & 3 deletions ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ PHP_FUNCTION(log1p)
}
/* }}} */

/* {{{ proto float|false log(float number, [float base])
/* {{{ proto float log(float number, [float base])
Returns the natural logarithm of the number, or the base log if base is specified */
PHP_FUNCTION(log)
{
Expand Down Expand Up @@ -710,8 +710,8 @@ PHP_FUNCTION(log)
}

if (base <= 0.0) {
php_error_docref(NULL, E_WARNING, "base must be greater than 0");
RETURN_FALSE;
zend_value_error("Base must be greater than 0");
return;
}

RETURN_DOUBLE(log(num) / log(base));
Expand Down
33 changes: 19 additions & 14 deletions ext/standard/tests/general_functions/ini_get_all.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@ pcre.recursion_limit=100000
<?php

var_dump(gettype(ini_get_all()));
var_dump(ini_get_all(""));
var_dump(ini_get_all("nosuchextension"));
try {
ini_get_all("");
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
try {
var_dump(ini_get_all("nosuchextension"));
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
var_dump(ini_get_all("reflection"));
var_dump(ini_get_all("pcre"));
var_dump(ini_get_all("pcre", false));
var_dump(ini_get_all("reflection", false));

var_dump(ini_get_all("", ""));
try {
ini_get_all("", "");
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

echo "Done\n";
?>
--EXPECTF--
--EXPECT--
string(5) "array"

Warning: ini_get_all(): Unable to find extension '' in %s on line %d
bool(false)

Warning: ini_get_all(): Unable to find extension 'nosuchextension' in %s on line %d
bool(false)
Unable to find extension ''
Unable to find extension 'nosuchextension'
array(0) {
}
array(3) {
Expand Down Expand Up @@ -70,7 +77,5 @@ array(3) {
}
array(0) {
}

Warning: ini_get_all(): Unable to find extension '' in %sini_get_all.php on line %d
bool(false)
Unable to find extension ''
Done
10 changes: 7 additions & 3 deletions ext/standard/tests/math/log_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Test log() - wrong params test log()
precision=14
--FILE--
<?php
log(36, -4);
try {
log(36, -4);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
?>
--EXPECTF--
Warning: log(): base must be greater than 0 in %s on line %d
--EXPECT--
Base must be greater than 0