Tags
PHP
I’m currently upgrading a large codebase to PHP 8.0. Here’s some documentation from the process to refactor the codebase to use a modern PHP approach.
Using array_key_exists() on objects is deprecated.
array_key_exists
no longer supports checking for properties defined within an object... instead use property_exists
Note: The arguments are swapped.
Each() deprecated
To replace each () deprecations you just use a foreach() loop:
while (list ($key, $val) = each ($_POST['selected'])) {
becomes
foreach ($_POST['selected'] as $key => $val) {
Required parameter $x follows optional parameter $y
PHP wants you to put required arguments first as parameters before optional arguments when defining a function’s argument list.
MYSQL → MSQLI Port
mysql_fetch_array
→ mysqli_fetch_array
mysql_num_rows
→ mysqli_num_rows
mysql_num_fields
→ mysqli_num_fields
mysql_fetch_row
→ mysqli_fetch_row
mysql_real_escape_string
→ mysqli_real_escape_string
mysql_fetch_assoc
→ mysqli_fetch_assoc
mysql_query
→ mysqli_query
mysql_insert_id
→ mysqli_insert_id
mysql_field_name
→ no replacement function, must be custom written, see https://stackoverflow.com/questions/14629636/mysql-field-name-to-the-new-mysqlimysql_connect
→ mysqli_connect
mysql_select_db
→ mysqli_select_db
mysqli_query
arguments are reversed. Go through each instance and reverse them!mysql_close
→ mysqli_close
mysql_free_result