From 29ce7a03ff4f86d5eb48cd9d3e9598ab11dfc9e9 Mon Sep 17 00:00:00 2001 From: Julien Chaffraix Date: Sat, 7 Dec 2024 17:41:30 -0800 Subject: [PATCH] [7/7] Remove array_get The function cannot be properly typed as it is and fixing this would take a while, removing it is shorter and better. The change removes usage in the last remaining files. It also removes 2 tests for the function that were converted instead of removed. TESTS=Tested site/author searching and some project updates. --- SETUP/tests/unittests/MiscUtilsTest.php | 14 -------------- activity_hub.php | 6 +++--- pinc/DPage.inc | 2 +- pinc/MARCRecord.inc | 2 +- pinc/Project.inc | 2 +- pinc/ProjectSearchForm.inc | 2 +- pinc/ProjectSearchResults.inc | 4 ++-- pinc/ProjectSearchResultsConfig.inc | 6 +++--- pinc/TableDocumentation.inc | 4 ++-- pinc/filter_project_list.inc | 8 ++++---- pinc/forum_interface_json.inc | 2 +- pinc/forum_interface_phpbb3.inc | 2 +- pinc/gradual.inc | 2 +- pinc/misc.inc | 5 ++--- pinc/post_processing.inc | 2 +- pinc/prefs_options.inc | 4 ++-- pinc/theme.inc | 6 +++--- pinc/upload_file.inc | 6 +++--- pinc/wordcheck_engine.inc | 12 ++++++------ tools/authors/search.inc | 6 +++--- tools/charsuites.php | 2 +- tools/modify_access.php | 4 ++-- tools/post_proofers/ppv_report.php | 14 +++++++------- tools/setlangcookie.php | 2 +- tools/site_search.php | 2 +- tools/upload_resumable_file.php | 12 ++++++------ tools/upload_text.php | 2 +- 27 files changed, 60 insertions(+), 75 deletions(-) diff --git a/SETUP/tests/unittests/MiscUtilsTest.php b/SETUP/tests/unittests/MiscUtilsTest.php index e7b908e902..1ea0e41087 100644 --- a/SETUP/tests/unittests/MiscUtilsTest.php +++ b/SETUP/tests/unittests/MiscUtilsTest.php @@ -4,20 +4,6 @@ class MiscUtilsTest extends PHPUnit\Framework\TestCase { - public function test_array_get_exists() - { - $arr = ["param" => "value"]; - $value = $arr["param"] ?? "default"; - $this->assertEquals($arr["param"], $value); - } - - public function test_array_get_doesnt_exists() - { - $arr = []; - $value = $arr["param"] ?? "default"; - $this->assertEquals("default", $value); - } - public function test_get_changed_fields_for_objects() { $obj1 = new stdClass(); diff --git a/activity_hub.php b/activity_hub.php index 0e5e5b17e5..cb0abf5d79 100644 --- a/activity_hub.php +++ b/activity_hub.php @@ -116,7 +116,7 @@ // show_filtered_numbers userSetting for use the next time they visit the // page. $user_filtered_projects_setting = $userSettings->get_boolean("show_filtered_numbers"); -$page_filtered_projects_setting = (array_get($_GET, "show_filtered", $user_filtered_projects_setting) == 1); +$page_filtered_projects_setting = (($_GET["show_filtered"] ?? $user_filtered_projects_setting) == 1); if ($user_filtered_projects_setting != $page_filtered_projects_setting) { $userSettings->set_boolean("show_filtered_numbers", $page_filtered_projects_setting); } @@ -344,9 +344,9 @@ function summarize_stage($stage, $desired_states, $show_filtered_projects = fals // (Use '@' to suppress "Undefined property" notice: // not every stage has a 'project_complete_state'.) if ($stage_state == @$stage->project_complete_state) { - $count = array_get($n_projects_transitioned_to_state_, $stage_state, 0); + $count = $n_projects_transitioned_to_state_[$stage_state] ?? 0; } else { - $count = array_get($n_projects_in_state_, $stage_state, 0); + $count = $n_projects_in_state_[$stage_state] ?? 0; $total_projects += $count; } diff --git a/pinc/DPage.inc b/pinc/DPage.inc index ec7a9b0b31..fcef4ce1ab 100644 --- a/pinc/DPage.inc +++ b/pinc/DPage.inc @@ -664,7 +664,7 @@ function get_normalize_page_text_changes(string $text, string $projectid): array $invalid_chars = get_invalid_characters($text, $project->get_valid_codepoints()); if ($invalid_chars) { - $whitespace_codepoints = array_get(get_utf8_to_ascii_codepoints(), " ", []); + $whitespace_codepoints = get_utf8_to_ascii_codepoints()[" "] ?? []; $unicode_whitespace_chars = array_map('voku\helper\UTF8::hex_to_chr', $whitespace_codepoints); $found_whitespace_chars = array_intersect(array_keys($invalid_chars), $unicode_whitespace_chars); if ($found_whitespace_chars) { diff --git a/pinc/MARCRecord.inc b/pinc/MARCRecord.inc index 4f6973f25b..ffb2e82d31 100644 --- a/pinc/MARCRecord.inc +++ b/pinc/MARCRecord.inc @@ -468,7 +468,7 @@ class MARCRecord // Character 6 - Type of record $leader = $this->record[0][1]; // The leader is always the first record. $code = substr($leader, 6, 1); - return array_get($this->type_of_record_array, $code, ""); + return $this->type_of_record_array[$code] ?? ""; } public function get_language(): string diff --git a/pinc/Project.inc b/pinc/Project.inc index a1d07f0883..aeecb8478f 100644 --- a/pinc/Project.inc +++ b/pinc/Project.inc @@ -754,7 +754,7 @@ class Project } $image_sources = load_image_sources(); - $imso_res = array_get($image_sources, (string)$this->image_source, null); + $imso_res = $image_sources[(string)$this->image_source] ?? null; if ($imso_res) { $this->_image_source_name = $imso_res['full_name']; $this->image_source_credit = $imso_res['credit']; diff --git a/pinc/ProjectSearchForm.inc b/pinc/ProjectSearchForm.inc index c6571deb9f..d612ed5f76 100644 --- a/pinc/ProjectSearchForm.inc +++ b/pinc/ProjectSearchForm.inc @@ -88,7 +88,7 @@ class ProjectSearchWidget public function get_sql_contribution() { - $value = array_get($_GET, $this->id, ''); + $value = $_GET[$this->id] ?? ''; if ($value == '') { return null; } diff --git a/pinc/ProjectSearchResults.inc b/pinc/ProjectSearchResults.inc index 75117091dc..2dada7242c 100644 --- a/pinc/ProjectSearchResults.inc +++ b/pinc/ProjectSearchResults.inc @@ -556,7 +556,7 @@ class ProjectSearchResults // else default to 'state' // store for next time $saved_sort = $this->userSettings->get_value("search:{$this->search_origin}.sort", " "); - $sort_param = array_get($_GET, "sort", $saved_sort); + $sort_param = $_GET["sort"] ?? $saved_sort; // parse and check if valid // remove terminating char A or D @@ -585,7 +585,7 @@ class ProjectSearchResults // get secondary sorting $saved_sec_sort = $this->userSettings->get_value("search:{$this->search_origin}.sort_sec", " "); - $this->sec_sort = array_get($_GET, "sec_sort", $saved_sec_sort); + $this->sec_sort = $_GET["sec_sort"] ?? $saved_sec_sort; $sec_sort_sql = $this->get_sort_sql($this->sec_sort); if (null == $sec_sort_sql) { $this->sec_sort = 'title'; diff --git a/pinc/ProjectSearchResultsConfig.inc b/pinc/ProjectSearchResultsConfig.inc index 5c099547c2..88950a0228 100644 --- a/pinc/ProjectSearchResultsConfig.inc +++ b/pinc/ProjectSearchResultsConfig.inc @@ -143,7 +143,7 @@ class ConfigForm extends ColumnData global $code_url, $pguser; echo "

$page_title

\n"; - $origin = array_get($_GET, 'origin', "$code_url/activity_hub.php"); + $origin = $_GET['origin'] ?? "$code_url/activity_hub.php"; echo "
@@ -212,7 +212,7 @@ class ConfigSaver extends ColumnData } // get the option values foreach ($option_data->options as $option) { - $value = array_get($_GET, $option->id, ''); + $value = $_GET[$option->id] ?? ''; $option->save_value($value); } } @@ -237,7 +237,7 @@ function handle_set_cols($show_view, $search_origin) $userSettings = & Settings::get_Settings($pguser); $config_saver = new ConfigSaver($userSettings, $search_origin); $config_saver->store_data(); - $origin = array_get($_GET, 'origin', "$code_url/activity_hub.php"); + $origin = $_GET['origin'] ?? "$code_url/activity_hub.php"; metarefresh(0, $origin); } } diff --git a/pinc/TableDocumentation.inc b/pinc/TableDocumentation.inc index 595e2f9328..e60e2d4e37 100644 --- a/pinc/TableDocumentation.inc +++ b/pinc/TableDocumentation.inc @@ -82,7 +82,7 @@ class TableDocumentation foreach ($contents as $row) { foreach ($row as $column => $value) { - $column_lengths[$column] = max(strlen($value), array_get($column_lengths, $column, strlen($column))); + $column_lengths[$column] = max(strlen($value), $column_lengths[$column] ?? strlen($column)); } } @@ -105,7 +105,7 @@ class TableDocumentation $output_row = '|'; foreach ($table_columns as $column) { - $output_row .= str_pad(array_get($row, $column, ''), $column_lengths[$column]) . '|'; + $output_row .= str_pad($row[$column] ?? '', $column_lengths[$column]) . '|'; } $output_table[] = $output_row; diff --git a/pinc/filter_project_list.inc b/pinc/filter_project_list.inc index 841938f4cb..b836ade26f 100644 --- a/pinc/filter_project_list.inc +++ b/pinc/filter_project_list.inc @@ -52,7 +52,7 @@ class ProjectFilterElement { echo "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 4512dd2438..4faee7d78e 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 4a0161f018..3ce3cb26b6 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 09c165698d..086ce67d6a 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 9594dc6c31..feeac518ca 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 4cdef5787d..941c06af1e 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 b3115613c9..908c9c510e 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 99337a7bff..e1ded78435 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 21578d1adc..2cd99b9659 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 c49d53ee93..601a1178ab 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 c0ae871c08..5aa98f8ebf 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 38c71f9fa6..d401659bbe 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 06103116ad..4882b181c8 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 cb25ca5dc3..0e728712e9 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 30a7c7a797..4bb0a4f94a 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 cd0b9fb771..df2cc757d1 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 aaa159a9a2..0f7c4f6aeb 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 7319924336..69db551752 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);