data, "difficulty", []);
+ $difficulty = $this->data["difficulty"] ?? [];
if (!count($difficulty)) {
echo " checked";
}
@@ -304,7 +304,7 @@ class ProjectSearchElement
public function get_sql_component()
{
- $values = array_get($this->data, $this->id, []);
+ $values = $this->data[$this->id] ?? [];
if (empty($values)) {
return "";
}
@@ -372,7 +372,7 @@ function get_project_filter_sql($pguser, $filter_type)
function get_lang_match($data)
{
// set a default if not set
- return array_get($data, "lang-match", "primwith");
+ return $data["lang-match"] ?? "primwith";
}
function save_data($pguser, $filter_type, $data)
diff --git a/pinc/forum_interface_json.inc b/pinc/forum_interface_json.inc
index 4512dd243..4faee7d78 100644
--- a/pinc/forum_interface_json.inc
+++ b/pinc/forum_interface_json.inc
@@ -241,7 +241,7 @@ function get_forum_user_details($username)
$return_data = [];
foreach ($interested_columns as $column) {
- $return_data[$column] = array_get($user, $column, null);
+ $return_data[$column] = $user[$column] ?? null;
}
return $return_data;
diff --git a/pinc/forum_interface_phpbb3.inc b/pinc/forum_interface_phpbb3.inc
index 4a0161f01..3ce3cb26b 100644
--- a/pinc/forum_interface_phpbb3.inc
+++ b/pinc/forum_interface_phpbb3.inc
@@ -346,7 +346,7 @@ function get_forum_user_details($username)
}
foreach ($interested_columns as $column) {
- $return_data[$column] = array_get($row, "user_$column", array_get($row, $column, null));
+ $return_data[$column] = $row["user_$column"] ?? ($row[$column] ?? null);
}
// phpBB 3.1 and later put data in phpbb_profile_fields_data with
diff --git a/pinc/gradual.inc b/pinc/gradual.inc
index 09c165698..086ce67d6 100644
--- a/pinc/gradual.inc
+++ b/pinc/gradual.inc
@@ -300,7 +300,7 @@ function encourage_highest_round(?string $username, $round_id = null): void
$mute_expire = $user_settings->get_value($mute_setting_key);
// if user has requested muting for this round, set the expire time
- if (array_get($_GET, $mute_query_param, "") == $round_target) {
+ if (($_GET[$mute_query_param] ?? "") == $round_target) {
$mute_expire = time() + 60 * 60 * 24 * $mute_days;
$user_settings->set_value($mute_setting_key, $mute_expire);
}
diff --git a/pinc/misc.inc b/pinc/misc.inc
index 9594dc6c3..feeac518c 100644
--- a/pinc/misc.inc
+++ b/pinc/misc.inc
@@ -24,8 +24,7 @@ use voku\helper\UTF8;
*/
function array_get($arr, $key, $default)
{
- // TODO(jchaffraix): Enable once we have no users in the codebase.
- // trigger_error("array_get() is deprecated, use the null coalescing operator instead", E_USER_DEPRECATED);
+ trigger_error("array_get() is deprecated, use the null coalescing operator instead", E_USER_DEPRECATED);
if (isset($arr[$key])) {
return $arr[$key];
} else {
@@ -61,7 +60,7 @@ function array_extract_field($array, $field)
*/
function array_get_as_array($array, $key, $default)
{
- $value = array_get($array, $key, $default);
+ $value = $array[$key] ?? $default;
if (!is_null($value) && !is_array($value)) {
$value = [$value];
}
diff --git a/pinc/post_processing.inc b/pinc/post_processing.inc
index 4cdef5787..941c06af1 100644
--- a/pinc/post_processing.inc
+++ b/pinc/post_processing.inc
@@ -50,7 +50,7 @@ function get_pp_projects_past_threshold($PPer = null)
}
if ($PPer) {
- return array_get($projects_grouped_by_PPer, $PPer, []);
+ return $projects_grouped_by_PPer[$PPer] ?? [];
} else {
return $projects_grouped_by_PPer;
}
diff --git a/pinc/prefs_options.inc b/pinc/prefs_options.inc
index b3115613c..908c9c510 100644
--- a/pinc/prefs_options.inc
+++ b/pinc/prefs_options.inc
@@ -81,9 +81,9 @@ function get_user_proofreading_font($interface = null)
if ($font_style_i == 1) { // other
$font_style = get_user_proofreading_font_other($interface);
} else {
- $font_style = array_get($proofreading_font_faces, $font_style_i, '');
+ $font_style = $proofreading_font_faces[$font_style_i] ?? '';
}
- $font_size = array_get($proofreading_font_sizes, $font_size_i, '');
+ $font_size = $proofreading_font_sizes[$font_size_i] ?? '';
$full_font_family = get_full_font_families($interface)[$font_style_i];
$font_size_family = $font_size ? $font_size : 'unset';
diff --git a/pinc/theme.inc b/pinc/theme.inc
index 99337a7bf..e1ded7843 100644
--- a/pinc/theme.inc
+++ b/pinc/theme.inc
@@ -312,7 +312,7 @@ function html_navbar()
// of the current request, so that after logging in, they are returned
// to (the "logged-in" version of) the page that's currently being built.
//
- $destination = array_get($_REQUEST, "destination", $_SERVER["REQUEST_URI"]);
+ $destination = $_REQUEST["destination"] ?? $_SERVER["REQUEST_URI"];
$login_form .= "
";
@@ -468,8 +468,8 @@ function resolve_headerbar_entries(array $entries): array
foreach ($entries as $entry) {
$text = $entry['text'];
- $title = array_get($entry, 'title', '');
- $target = array_get($entry, 'target', null);
+ $title = $entry['title'] ?? '';
+ $target = $entry['target'] ?? null;
if (!empty($entry['url'])) {
// ensure we have a full url, if not prefix the $code_url
diff --git a/pinc/upload_file.inc b/pinc/upload_file.inc
index 21578d1ad..2cd99b965 100644
--- a/pinc/upload_file.inc
+++ b/pinc/upload_file.inc
@@ -28,7 +28,7 @@ define("RESUMABLE_UPLOAD_SIZE", 1024 * 1024 * 1024); // 1GB
function detect_too_large()
{
if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) &&
- empty($_FILES) && array_get($_SERVER, 'CONTENT_LENGTH', 0) > 0) {
+ empty($_FILES) && ($_SERVER['CONTENT_LENGTH'] ?? 0) > 0) {
throw new LengthException(sprintf(_("Uploaded file is too large. Maximum file size is %s."), humanize_bytes(get_max_upload_size())));
}
}
@@ -191,8 +191,8 @@ function validate_uploaded_file($verbose)
} else {
// resumable upload
$root_staging_dir = "/tmp/resumable_uploads";
- $original_name = array_get($_POST, "resumable_filename", "");
- $identifier = array_get($_POST, "resumable_identifier", "");
+ $original_name = $_POST["resumable_filename"] ?? "";
+ $identifier = $_POST["resumable_identifier"] ?? "";
$hashed_filename = md5($identifier);
$file_path = "$root_staging_dir/$hashed_filename";
if (!file_exists($file_path)) {
diff --git a/pinc/wordcheck_engine.inc b/pinc/wordcheck_engine.inc
index c49d53ee9..601a1178a 100644
--- a/pinc/wordcheck_engine.inc
+++ b/pinc/wordcheck_engine.inc
@@ -223,8 +223,8 @@ function get_bad_words_for_text($text, $languages, $word_lists = [])
// The site
{
- $acc->remove_good_words(array_get($word_lists, "site_good", []));
- $acc->add_bad_words(array_get($word_lists, "site_bad", []), WC_SITE);
+ $acc->remove_good_words($word_lists["site_good"] ?? []);
+ $acc->add_bad_words($word_lists["site_bad"] ?? [], WC_SITE);
$acc->add_bad_words(
get_bad_words_via_pattern($input_words_w_freq, $languages),
@@ -234,14 +234,14 @@ function get_bad_words_for_text($text, $languages, $word_lists = [])
// The project
{
- $acc->remove_good_words(array_get($word_lists, "project_good", []));
+ $acc->remove_good_words($word_lists["project_good"] ?? []);
- $acc->add_bad_words(array_get($word_lists, "project_bad", []), WC_PROJECT);
+ $acc->add_bad_words($word_lists["project_bad"] ?? [], WC_PROJECT);
}
// The page
{
- $acc->remove_good_words(array_get($word_lists, "adhoc_good", []));
+ $acc->remove_good_words($word_lists["adhoc_good"] ?? []);
}
return [$input_words_w_freq, $acc->words, $acc->messages];
@@ -480,7 +480,7 @@ function get_bad_words_via_pattern($input_words_w_freq, $languages)
];
$exceptions = [];
foreach ($langcode3s as $langcode3) {
- $exceptions[] = array_get($exceptions_for_lang, $langcode3, "");
+ $exceptions[] = $exceptions_for_lang[$langcode3] ?? "";
}
$exceptions = join('|', $exceptions);
$exceptions_pattern = "/^($exceptions)$/u";
diff --git a/tools/authors/search.inc b/tools/authors/search.inc
index c0ae871c0..5aa98f8eb 100644
--- a/tools/authors/search.inc
+++ b/tools/authors/search.inc
@@ -144,9 +144,9 @@ function sql_like_encode(string $str): string
function echo_search_form(): void
{
global $last_name, $other_names;
- $view = array_get($_REQUEST, 'view', null);
- $orderby = array_get($_REQUEST, 'orderby', null);
- $desc = array_get($_REQUEST, 'desc', null);
+ $view = $_REQUEST['view'] ?? null;
+ $orderby = $_REQUEST['orderby'] ?? null;
+ $desc = $_REQUEST['desc'] ?? null;
echo "
" . _("Search") . "
";
echo "
" . _('Case insensitive.') . " ";
echo sprintf(
diff --git a/tools/charsuites.php b/tools/charsuites.php
index 38c71f9fa..d401659bb 100644
--- a/tools/charsuites.php
+++ b/tools/charsuites.php
@@ -9,7 +9,7 @@
require_login();
-$charsuite_name = array_get($_GET, "charsuite", null);
+$charsuite_name = $_GET["charsuite"] ?? null;
$projectid = get_projectID_param($_REQUEST, "projectid", true);
$charsuite = null;
diff --git a/tools/modify_access.php b/tools/modify_access.php
index 06103116a..4882b181c 100644
--- a/tools/modify_access.php
+++ b/tools/modify_access.php
@@ -8,8 +8,8 @@
require_login();
-$subject_username = array_get($_POST, 'subject_username', null);
-$notify_user = array_get($_POST, 'notify_user', null);
+$subject_username = $_POST['subject_username'] ?? null;
+$notify_user = $_POST['notify_user'] ?? null;
$user = new User($subject_username);
diff --git a/tools/post_proofers/ppv_report.php b/tools/post_proofers/ppv_report.php
index cb25ca5dc..0e728712e 100644
--- a/tools/post_proofers/ppv_report.php
+++ b/tools/post_proofers/ppv_report.php
@@ -279,7 +279,7 @@ function number_box($id, $label, $options = [])
global $action;
$problem = "";
if ($action == HANDLE_ENTRY_FORM_SUBMISSION) {
- $arg = array_get($_POST, $id, '');
+ $arg = $_POST[$id] ?? '';
if ($id == 'kb_size') {
if ($arg == "") {
@@ -316,7 +316,7 @@ function _textbox($id, $label, $options = [])
if ($action == SHOW_BLANK_ENTRY_FORM) {
$value = '';
} elseif ($action == HANDLE_ENTRY_FORM_SUBMISSION) {
- $value = array_get($_POST, $id, '');
+ $value = $_POST[$id] ?? '';
}
if ($value == '') {
@@ -325,9 +325,9 @@ function _textbox($id, $label, $options = [])
$value_attr = sprintf(" value='%s'", attr_safe($value));
}
- $size = array_get($options, 'size', 3);
- $use_a_label_element = array_get($options, 'use_a_label_element', false);
- $put_label_on_left = array_get($options, 'put_label_on_left', false);
+ $size = $options['size'] ?? 3;
+ $use_a_label_element = $options['use_a_label_element'] ?? false;
+ $put_label_on_left = $options['put_label_on_left'] ?? false;
$input_element = "";
@@ -353,7 +353,7 @@ function comment_box($id)
if ($action == SHOW_BLANK_ENTRY_FORM) {
$text = '';
} elseif ($action == HANDLE_ENTRY_FORM_SUBMISSION) {
- $text = array_get($_POST, $id, '');
+ $text = $_POST[$id] ?? '';
}
$esc_text = html_safe($text);
@@ -939,7 +939,7 @@ function report_recommendations($recommendations)
function report_comments($base_indent, $id, $label)
{
- $comments = array_get($_POST, $id, '');
+ $comments = $_POST[$id] ?? '';
if (empty($comments)) {
return "";
}
diff --git a/tools/setlangcookie.php b/tools/setlangcookie.php
index 30a7c7a79..4bb0a4f94 100644
--- a/tools/setlangcookie.php
+++ b/tools/setlangcookie.php
@@ -9,7 +9,7 @@
// These should always be set if the user got here correctly.
// They won't be set if someone accesses this URL directly.
$language = get_enumerated_param($_POST, 'lang', '', $lang_options);
-$location = array_get($_POST, 'returnto', "$code_url/default.php");
+$location = $_POST['returnto'] ?? "$code_url/default.php";
if ($language) {
// set the cookie
diff --git a/tools/site_search.php b/tools/site_search.php
index cd0b9fb77..df2cc757d 100644
--- a/tools/site_search.php
+++ b/tools/site_search.php
@@ -6,7 +6,7 @@
require_login();
-$query = trim(array_get($_GET, "q", "help"));
+$query = trim($_GET["q"] ?? "help");
// "help" is just a string to get us here, but we don't want to keep it
if ($query == "help") {
diff --git a/tools/upload_resumable_file.php b/tools/upload_resumable_file.php
index aaa159a9a..0f7c4f6ae 100644
--- a/tools/upload_resumable_file.php
+++ b/tools/upload_resumable_file.php
@@ -10,14 +10,14 @@
// staging directory for resumable uploads
$root_staging_dir = "/tmp/resumable_uploads";
-$identifier = array_get($_REQUEST, "resumableIdentifier", "");
+$identifier = $_REQUEST["resumableIdentifier"] ?? "";
// create a sanitized file name from the identifier
$hashed_filename = md5($identifier);
-$filename = array_get($_REQUEST, "resumableFilename", "");
-$chunk_number = array_get($_REQUEST, "resumableChunkNumber", "");
-$chunk_size = array_get($_REQUEST, "resumableChunkSize", "");
-$total_chunks = array_get($_REQUEST, "resumableTotalChunks", 0);
-$total_size = array_get($_REQUEST, "resumableTotalSize", 0);
+$filename = $_REQUEST["resumableFilename"] ?? "";
+$chunk_number = $_REQUEST["resumableChunkNumber"] ?? "";
+$chunk_size = $_REQUEST["resumableChunkSize"] ?? "";
+$total_chunks = $_REQUEST["resumableTotalChunks"] ?? 0;
+$total_size = $_REQUEST["resumableTotalSize"] ?? 0;
// use a different name for directory so we can put final file
// in $root_staging_dir and delete $staging_dir
diff --git a/tools/upload_text.php b/tools/upload_text.php
index 731992433..69db55175 100644
--- a/tools/upload_text.php
+++ b/tools/upload_text.php
@@ -22,7 +22,7 @@
// days not given (defaults to 0): replace file only
$days = get_integer_param($_REQUEST, 'days', 0, 0, 56);
$action = @$_REQUEST['action'];
-$postcomments = array_get($_POST, 'postcomments', "");
+$postcomments = $_POST['postcomments'] ?? "";
$project = new Project($projectid);