不推荐使用:自动将false转换为数组不推荐使用
我是PHP 8 的新手
我看到的所有解释都与会话有关,而不是从数据库中检索的数据。
此函数可以很好地写入缓存,并且Deprecated消息将消失。每次清除缓存时,我都会看到一次消息,然后它就会消失。一旦它开始从缓存文件中读取,我就再也看不到消息了。
它保存缓存文件,然后系统像从未发生过的那样使用它。在这种情况下,我不理解将false自动转换为数组的实际含义。
有问题的线路:
$sentinel[$config_name]=$config_value;
还有什么其他方法可以做到这一点?
function abget_configs(){
global $prefix, $db, $cache;
static $sentinel;
if(isset($sentinel)) return $sentinel;
if(!($sentinel = $cache->load('titanium_sentinel', 'config'))) {
$configresult = $db->sql_query("SELECT `config_name`, `config_value` FROM `".$prefix."_nsnst_config`");
while (list($config_name, $config_value) = $db->sql_fetchrow($configresult)) {
$sentinel[$config_name] = $config_value;
echo $config_name.': '.$sentinel[$config_name].'</br>';
}
$db->sql_freeresult($configresult);
$cache->save('titanium_sentinel', 'config', $sentinel);
}
return $sentinel;
}
输出:
admin_contact: admin@php-nuke.coders.exchange
block_perpage: 50
block_sort_column: date
block_sort_direction: desc
crypt_salt: N$
display_link: 3
display_reason: 3
force_nukeurl: 0
help_switch: 1
htaccess_path: /home/phpnuke/public_html/.htaccess
http_auth: 0
lookup_link: admin.php?op=ABIpCheck&domain=
page_delay: 1
prevent_dos: 1
proxy_reason: abuse_admin.tpl
proxy_switch: 0
santy_protection: 1
self_expire: 0
site_reason: admin_site_reason.tpl
site_switch: 0
staccess_path: /home/phpnuke/public_html/.staccess
track_active: 1
track_max: 604800
track_perpage: 50
track_sort_column: ip_long
track_sort_direction: desc
ip_reason: admin_ip_reason.tpl
ip_switch: 0
ftaccess_path: /home/phpnuke/public_html/.ftaccess
flood_delay: 2
disable_switch: 0
track_clear: 1673827200
blocked_clear: 0
version_check: $checktime
version_newest: 2.6.09
version_number: 2.6.09
dump_directory: includes/cache/
show_right: 0
test_switch: 0
var_dump($sentinel)
array(39) { ["admin_contact"]=> string(30) "admin@php-nuke.coders.exchange" ["block_perpage"]=> string(2) "50" ["block_sort_column"]=> string(4) "date" ["block_sort_direction"]=> string(4) "desc" ["crypt_salt"]=> string(2) "N$" ["display_link"]=> string(1) "3" ["display_reason"]=> string(1) "3" ["force_nukeurl"]=> string(1) "0" ["help_switch"]=> string(1) "1" ["htaccess_path"]=> string(35) "/home/phpnuke/public_html/.htaccess" ["http_auth"]=> string(1) "0" ["lookup_link"]=> string(30) "admin.php?op=ABIpCheck&domain=" ["page_delay"]=> string(1) "1" ["prevent_dos"]=> string(1) "1" ["proxy_reason"]=> string(15) "abuse_admin.tpl" ["proxy_switch"]=> string(1) "0" ["santy_protection"]=> string(1) "1" ["self_expire"]=> string(1) "0" ["site_reason"]=> string(21) "admin_site_reason.tpl" ["site_switch"]=> string(1) "0" ["staccess_path"]=> string(35) "/home/phpnuke/public_html/.staccess" ["track_active"]=> string(1) "1" ["track_max"]=> string(6) "604800" ["track_perpage"]=> string(2) "50" ["track_sort_column"]=> string(7) "ip_long" ["track_sort_direction"]=> string(4) "desc" ["ip_reason"]=> string(19) "admin_ip_reason.tpl" ["ip_switch"]=> string(1) "0" ["ftaccess_path"]=> string(35) "/home/phpnuke/public_html/.ftaccess" ["flood_delay"]=> string(1) "2" ["disable_switch"]=> string(1) "0" ["track_clear"]=> string(10) "1673827200" ["blocked_clear"]=> string(1) "0" ["version_check"]=> string(10) "$checktime" ["version_newest"]=> string(6) "2.6.09" ["version_number"]=> string(6) "2.6.09" ["dump_directory"]=> string(15) "includes/cache/" ["show_right"]=> string(1) "0" ["test_switch"]=> string(1) "0" }
这是一个简单的修复方法
function abget_configs(){
global $prefix, $db, $cache;
static $sentinel;
if(isset($sentinel)) return $sentinel;
if(!($sentinel = $cache->load('titanium_sentinel', 'config'))) {
# Deprecated: Automatic conversion of false to array is deprecated Fix Start
$sentinel = [];
$configresult = [];
# Deprecated: Automatic conversion of false to array is deprecated Fix End
$configresult = $db->sql_query("SELECT `config_name`, `config_value` FROM `".$prefix."_nsnst_config`");
while (list($config_name, $config_value) = $db->sql_fetchrow($configresult)) {
$sentinel[$config_name] = $config_value;
echo $config_name.': '.$sentinel[$config_name].'</br>';
}
$db->sql_freeresult($configresult);
//var_dump($sentinel);
$cache->save('titanium_sentinel', 'config', $sentinel);
}
return $sentinel;
}