What are best practices for ensuring compatibility of a 20-year-old PHP script with newer PHP versions like 7.3?

To ensure compatibility of a 20-year-old PHP script with newer PHP versions like 7.3, it is important to update deprecated functions, replace outdated syntax, and address any security vulnerabilities. This can be achieved by refactoring the codebase, using modern PHP best practices, and testing thoroughly to catch any compatibility issues.

// Example of updating deprecated functions in a 20-year-old PHP script
// Replace mysql_connect with mysqli_connect
$mysqli = mysqli_connect("localhost", "username", "password", "database");

// Replace mysql_query with mysqli_query
$result = mysqli_query($mysqli, "SELECT * FROM table");

// Use prepared statements to prevent SQL injection
$stmt = mysqli_prepare($mysqli, "SELECT * FROM table WHERE id = ?");
mysqli_stmt_bind_param($stmt, "i", $id);
mysqli_stmt_execute($stmt);