# Resolving common PHP upgrade issues

> Fix common problems after upgrading PHP, such as removed functions, short tags, extension changes and error handling.

Source: https://helpcenter.ruachost.com/developers/php/resolving-common-php-upgrade-issues/

When upgrading PHP versions on **ruachost.com**, you may encounter compatibility problems with existing scripts or applications. This guide outlines common issues and how to resolve them.

## Why Issues Occur

- **Deprecated functions**: Older PHP versions may use functions removed in newer releases.
- **Changed default settings**: Configuration directives may behave differently.
- **Extension compatibility**: Some extensions are no longer bundled or require manual installation.
- **Syntax changes**: Certain language constructs are updated or removed.

## Common Issues and Fixes

### 1. Deprecated or Removed Functions

- Functions like `mysql_connect()` are removed in PHP 7+.
- **Fix**: Replace with `mysqli` or `PDO`.

  ```
  // Old
  $conn = mysql_connect("localhost", "user", "pass");

  // New
  $conn = new mysqli("localhost", "user", "pass", "database");
  ```

### 2. Short Tags Disabled

- Some servers disable `<? ?>` short tags.
- **Fix**: Use full tags `<?php ?>` or enable short tags in `php.ini`.

### 3. Extension Changes

- Extensions like `mcrypt` are removed in PHP 7.2+.
- **Fix**: Use `openssl` or `sodium` for encryption.

### 4. Error Handling Differences

- `set_error_handler()` behavior may differ.
- **Fix**: Update error handling code to match new standards.

### 5. Default Charset

- PHP 5.6+ defaults to UTF‑8.
- **Fix**: Ensure your database and scripts use consistent encoding (`utf8mb4`).

### 6. Session Handling

- Session storage paths may change.
- **Fix**: Verify `session.save_path` in `php.ini` and adjust permissions.

### 7. Strict Variable Handling

- PHP 7 introduces stricter type checks.
- **Fix**: Update code to match expected types or use type declarations.

> **Best Practices:**
- Always back up your site before upgrading.
- Test upgrades in a staging environment.
- Review `error_log` for warnings and notices.
- Use `phpinfo()` to confirm settings after upgrade.
- Keep frameworks and CMSs updated to their latest versions.
