yiisoft / yii

Yii PHP Framework 1.1.x
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
4.85k stars 2.28k forks source link

PHP 8.3 Compatibility #4552

Open sandippingle opened 3 months ago

sandippingle commented 3 months ago

What steps will reproduce the problem?

PHP Deprecated the following features/functions in their release of 8.3:

https://www.php.net/manual/en/migration83.deprecated.php

Saner Increment/Decrement operators

Reflection

Calling ReflectionProperty::setValue() with only one parameter is deprecated. To set static properties, pass null as the first parameter.

Possibly impacted code:

public function setLocaleDataPath($value)
    {
        $property=new ReflectionProperty($this->localeClass,'dataPath');
        $property->setValue($value);
    }

SQLite3

Using exceptions is now preferred, warnings will be removed in the future. Calling SQLite3::enableExceptions(false) will trigger a deprecation warning in this version.

How can we plan PHP 8.3 compatibility?

Additional info

Q A
Yii version 1.1.29
PHP version 8.3
Operating system Linux
marcovtwout commented 3 months ago

Regarding the reflection deprecation, that point seems valid. Those lines could probably be replaced with:

$class=new ReflectionClass($this->localeClass);
$class->setStaticPropertyValue('dataPath',$value);

Regarding SQLite3 enableExceptions(), I don't see that being used anywhere in framework code?

TheGithubDev commented 1 month ago

PHP 8.3 introduces several deprecations that impact the current codebase. Specifically:

Proposed Changes

  1. Saner Increment/Decrement Operators

    • Action: Conduct a thorough review of the codebase to identify any usages of increment/decrement operators that rely on deprecated behaviors. Update the code to align with PHP 8.3's expectations.
    • Impact: Ensure no deprecated warnings are triggered by these operators.
  2. ReflectionProperty::setValue() Method

    • Action: Modify the setLocaleDataPath method to comply with the new requirement of passing null as the first parameter when setting static properties.
    • Implementation:
      public function setLocaleDataPath($value)
      {
       $property = new ReflectionProperty($this->localeClass, 'dataPath');
       if ($property->isStatic()) {
           $property->setValue(null, $value);
       } else {
           $property->setValue($this, $value);
       }
      }
    • Impact: Ensure the method works correctly with both static and non-static properties under PHP 8.3.
  3. SQLite3 Exception Handling

    • Action: Refactor the SQLite3 usage to utilize exceptions properly, removing any calls to SQLite3::enableExceptions(false).
    • Implementation:
      try {
       $db = new SQLite3('database.db');
       $db->enableExceptions(true);
      } catch (Exception $e) {
       echo 'Caught exception: ', $e->getMessage(), "\n";
      }
    • Impact: Properly handle exceptions and avoid deprecated warnings related to SQLite3.

Implementation Plan

  1. Code Audit and Refactoring

    • Perform a comprehensive audit of the codebase to identify any usage of deprecated features/functions.
    • Refactor the identified areas according to the proposed changes.
  2. Testing

    • Set up a testing environment with PHP 8.3.
    • Run unit and integration tests to ensure all functionality works as expected.
    • Address any issues that arise during testing.
  3. Update Dependencies

    • Check all dependencies for PHP 8.3 compatibility.
    • Update any third-party libraries and frameworks to their latest versions that support PHP 8.3.
  4. Documentation

    • Update project documentation to reflect changes made for PHP 8.3 compatibility.
    • Include information on any new exception handling logic and refactored methods.

      4554

Hope this helps out!

Regards.

marcovtwout commented 1 month ago

@TheGithubDev was the post above generated with AI? Is SQLite3 enableExceptions() used anywhere in framework code?