Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 / 8.2 Compatibility #7225

Merged
merged 37 commits into from
Oct 27, 2022
Merged

PHP 8.1 / 8.2 Compatibility #7225

merged 37 commits into from
Oct 27, 2022

Conversation

swissspidy
Copy link
Collaborator

@swissspidy swissspidy commented Aug 25, 2022

Summary

Since we use parts of the AMP plugin in the Web Stories plugin, it would be reassuring for us if it works more or less seamlessly with PHP 8.1 and 8.2.

PHP 8.2 compatibility is currently blocked by work on WordPress core itself.

Even PHP 8.1 is not seamless due to the conflict with the Requests library.

See also ampproject/amp-toolbox-php#533 (for which an update to dev-main is included in this PR)

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

* origin/develop: (32 commits)
  Bump classnames from 2.3.1 to 2.3.2
  Bump webpack-remove-empty-scripts from 1.0.0 to 1.0.1
  Bump wp-cli/extension-command from 2.1.6 to 2.1.7
  Bump postcss-preset-env from 7.8.1 to 7.8.2
  Update jest snapshots after @wordpress/components package updates
  Update Gutenberg package dependencies
  Bump sirbrillig/phpcs-variable-analysis from 2.11.7 to 2.11.8
  Fix failing tests on trunk due to webp support
  Remove avoidable isset() check
  Bump @babel/core from 7.18.13 to 7.19.0
  Bump eslint from 8.23.0 to 8.23.1
  Bump eslint-plugin-jest from 27.0.1 to 27.0.4
  Bump eslint-plugin-react from 7.31.1 to 7.31.8
  Bump webpack-remove-empty-scripts from 0.8.1 to 1.0.0
  Bump css-minimizer-webpack-plugin from 4.0.0 to 4.1.0
  Update Gutenberg package dependencies
  Bump postcss-preset-env from 7.8.0 to 7.8.1
  Update test snapshots
  Update mask-type attribute with mask-type css prop
  Bump uuid from 8.3.2 to 9.0.0
  ...
amp.php Outdated Show resolved Hide resolved
Co-authored-by: Weston Ruter <[email protected]>
@swissspidy
Copy link
Collaborator Author

Something to fix in PHP-CSS-Parser:

PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in /tmp/wordpress/src/wp-content/plugins/amp/vendor/sabberworm/php-css-parser/src/Parsing/ParserState.php on line 129
PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in /tmp/wordpress/src/wp-content/plugins/amp/vendor/sabberworm/php-css-parser/src/Parsing/ParserState.php on line 129
PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in /tmp/wordpress/src/wp-content/plugins/amp/vendor/sabberworm/php-css-parser/src/Parsing/ParserState.php on line 130
PHP Deprecated:  Using ${var} in strings is deprecated, use {$var} instead in /tmp/wordpress/src/wp-content/plugins/amp/vendor/sabberworm/php-css-parser/src/Parsing/ParserState.php on line 131

@swissspidy
Copy link
Collaborator Author

This bug was just fixed in Gutenberg yesterday: WordPress/gutenberg#44829
So this will get resorted once the next GB version is released.

FYI, while GB 14.4 was released today, that bugfix won't be included until version 14.5 (due by November 07, 2022)

@swissspidy
Copy link
Collaborator Author

Unit test (with coverage): PHP 7.4, WP latest

This required status check needs to be removed/changed, since now the coverage is done with PHP 8.0 instead.

@westonruter
Copy link
Member

Unit test (with coverage): PHP 7.4, WP latest

This required status check needs to be removed/changed, since now the coverage is done with PHP 8.0 instead.

Removed (to be changed after merge)

includes/validation/class-amp-validation-manager.php Outdated Show resolved Hide resolved
* @param string $header_value Header value.
* @return bool Whether header contains the value "hit"
*/
private static function cache_hit_callback( string $header_value ): bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was introduced in bd2ee42 apparently to deal with a PHPCS bug, and not due to any fault of the code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

Comment on lines -10 to -30
// Detect where to load the WordPress tests environment from.
if ( false !== getenv( 'WP_TESTS_DIR' ) ) {
$_test_root = getenv( 'WP_TESTS_DIR' );
} elseif ( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
$_test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit';
} elseif ( file_exists( '/tmp/wordpress-tests/includes/bootstrap.php' ) ) {
$_test_root = '/tmp/wordpress-tests';
} elseif ( file_exists( '/var/www/wordpress-develop/tests/phpunit' ) ) {
$_test_root = '/var/www/wordpress-develop/tests/phpunit';
} else {
$_test_root = dirname( dirname( dirname( dirname( TESTS_PLUGIN_DIR ) ) ) ) . '/tests/phpunit';
}

// When run in wp-env context, set the test config file path.
if ( ! defined( 'WP_TESTS_CONFIG_FILE_PATH' ) && false !== getenv( 'WP_PHPUNIT__TESTS_CONFIG' ) ) {
define( 'WP_TESTS_CONFIG_FILE_PATH', getenv( 'WP_PHPUNIT__TESTS_CONFIG' ) );
}

require_once TESTS_PLUGIN_DIR . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php';
$_tests_dir = Yoast\WPTestUtils\WPIntegration\get_path_to_wp_test_dir();
require_once $_test_root . '/includes/functions.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

Shall we wait to merge until Gutenberg 14.5 is released?

@westonruter westonruter added this to the v2.3.1 milestone Oct 26, 2022
@swissspidy
Copy link
Collaborator Author

I don‘t see an issue with merging this already, but up to you

@westonruter
Copy link
Member

The issue is the failing tests will make it hard to identify problems with other PRs being opened in the next ~2 weeks.

@swissspidy
Copy link
Collaborator Author

You can also just temporarily skip these two tests

@westonruter westonruter merged commit 761c716 into develop Oct 27, 2022
@westonruter westonruter deleted the try-php81-php82 branch October 27, 2022 21:43
@westonruter
Copy link
Member

Gutenberg updated in #7331. PHPUnit tests now all pass. 🎉

@westonruter westonruter modified the milestones: v2.3.1, v2.4 Jan 26, 2023
@pavanpatil1
Copy link

Tested it with PHP 8.1 and 8.2, Plugin functionality seems working fine with both the PHP versions. However, there are some deprecation warnings are visible in both versions.

PHP8.1

PHP Deprecated:  header(): Passing null to parameter #3 ($response_code) of type int is deprecated in C:\Users\win 10\Local Sites\php8amp\app\public\wp-content\plugins\amp\includes\class-amp-http.php on line 95

PHP8.2

PHP Deprecated:  Return type of AMP_Validation_Callback_Wrapper::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/htdocs/current/wp-content/plugins/amp/includes/validation/class-amp-validation-callback-wrapper.php on line 425
PHP Deprecated:  Creation of dynamic property AmpProject\Optimizer\Configuration\MinifyHtmlConfiguration::$minifyAmpScript is deprecated in /var/www/htdocs/current/wp-content/plugins/amp/vendor/ampproject/amp-toolbox/src/Optimizer/Configuration/BaseTransformerConfiguration.php on line 40
PHP Deprecated:  header(): Passing null to parameter #3 ($response_code) of type int is deprecated in /var/www/htdocs/current/wp-content/plugins/amp/includes/class-amp-http.php on line 92

@westonruter
Copy link
Member

In regards to:

PHP Deprecated:  header(): Passing null to parameter #3 ($response_code) of type int is deprecated in C:\Users\win 10\Local Sites\php8amp\app\public\wp-content\plugins\amp\includes\class-amp-http.php on line 95

This is the code in question:

public static function send_header( $name, $value, $args = [] ) {
$args = array_merge(
[
'replace' => true,
'status_code' => null,
],
$args
);
self::$headers_sent[] = array_merge( compact( 'name', 'value' ), $args );
if ( headers_sent() ) {
return false;
}
header(
sprintf( '%s: %s', $name, $value ),
$args['replace'],
$args['status_code']
);
return true;
}

It looks like all that is required is:

- 				'status_code' => null,
+ 				'status_code' => 0,

@westonruter
Copy link
Member

In regards to:

PHP Deprecated:  Return type of AMP_Validation_Callback_Wrapper::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/htdocs/current/wp-content/plugins/amp/includes/validation/class-amp-validation-callback-wrapper.php on line 425

I'm confused since it does have #[\ReturnTypeWillChange]:

/**
* Offset unset.
*
* @param mixed $offset Offset.
*/
#[\ReturnTypeWillChange]
public function offsetUnset( $offset ) {
if ( ! is_array( $this->callback['function'] ) ) {
return;
}
unset( $this->callback['function'][ $offset ] );
}

@westonruter
Copy link
Member

westonruter commented Feb 6, 2023

And finally, in regards to:

PHP Deprecated:  Creation of dynamic property AmpProject\Optimizer\Configuration\MinifyHtmlConfiguration::$minifyAmpScript is deprecated in /var/www/htdocs/current/wp-content/plugins/amp/vendor/ampproject/amp-toolbox/src/Optimizer/Configuration/BaseTransformerConfiguration.php on line 40

Looks like this is something that was missed in ampproject/amp-toolbox-php#533.

See example at https://github.com/ampproject/amp-toolbox-php/pull/533/files#diff-12262a92eb1759cfc297901a94d3e5ab9edc9862154fb003e21f7b80719a7fc2

@westonruter
Copy link
Member

Actually, it seems like this was tested without the latest amp-toolbox-php. Line 40 in BaseTransformerConfiguration.php is the following in v0.11.2:

$this->$key = $this->validate($key, $value);

Whereas in main it is the following:

$this->allowedKeys = $this->getAllowedKeys();

I just tried downloading the most recent development build and I see that the former is present as expected.

@pavanpatil1 Could you please re-test, making sure you have the latest development build installed (as for all current QA)?

@thelovekesh
Copy link
Collaborator

I checked with PHP 8.2 but was unable to get any deprecation warnings other than the

[06-Feb-2023 19:38:52 UTC] PHP Deprecated:  header(): Passing null to parameter #3 ($response_code) of type int is deprecated in /app/public/content/plugins/amp/includes/class-amp-http.php on line 92

@pavanpatil1
Copy link

QA passed ✅

Tested it with the latest development build. Functionality was working as expected before now the deprecation warnings are not visible now with both v8.1 and 8.2. solved in this PR.

@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants