php-src/Zend/tests/bug69315.phpt
Nikita Popov 53eee290b6 Completely remove disabled functions from function table
Currently, disabling a function only replaces the internal
function handler with one that throws a warning, and a few
places in the engine special-case such functions, such as
function_exists. This leaves us with a Schrödinger's function,
which both does not exist (function_exists returns false) and
does exist (you cannot define a function with the same name).
In particular, this prevents the implementation of robust
polyfills, as reported in https://bugs.php.net/bug.php?id=79382:

    if (!function_exists('getallheaders')) {
        function getallheaders(...) { ... }
    }

If getallheaders() is a disabled function, this code will break.

This patch changes disable_functions to remove the functions from
the function table completely. For all intents and purposes, it
will look like the function does not exist.

This also renders two bits of PHP functionality obsolete and thus
deprecated:

 * ReflectionFunction::isDisabled(), as it will no longer be
   possible to construct the ReflectionFunction of a disabled
   function in the first place.
 * get_defined_functions() with $exclude_disabled=false, as
   get_defined_functions() now never returns disabled functions.

Fixed bug #79382.

Closes GH-5473.
2020-04-30 09:53:57 +02:00

51 lines
1.0 KiB
PHP

--TEST--
Bug #69315 (disable_functions behaviors inconsistently)
--INI--
disable_functions=strlen,defined,call_user_func,constant,is_string
--FILE--
<?php
var_dump(function_exists("strlen"));
var_dump(is_callable("strlen"));
try {
var_dump(strlen("xxx"));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(defined("PHP_VERSION"));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(constant("PHP_VERSION"));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(call_user_func("strlen"));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(is_string("xxx"));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_dump(is_string());
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
bool(false)
bool(false)
Call to undefined function strlen()
Call to undefined function defined()
Call to undefined function constant()
Call to undefined function call_user_func()
Call to undefined function is_string()
Call to undefined function is_string()