From 5bca4a6bbb6ff9c97bd68264c5952a4d23262464 Mon Sep 17 00:00:00 2001 From: Philip John Date: Mon, 30 Oct 2023 12:51:19 +0000 Subject: [PATCH 1/4] PHP 8.2: Fix Creation of dynamic property deprecation notices --- object-cache.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/object-cache.php b/object-cache.php index b0b4d0f..3c6d02d 100644 --- a/object-cache.php +++ b/object-cache.php @@ -1036,9 +1036,9 @@ function failure_callback( $host, $port ) { function salt_keys( $key_salt ) { if ( strlen( $key_salt ) ) { - $this->key_salt = $key_salt . ':'; + $this->__set( 'key_salt', $key_salt . ':' ); } else { - $this->key_salt = ''; + $this->__set( 'key_salt', '' ); } } @@ -1104,8 +1104,8 @@ function __construct() { global $blog_id, $table_prefix; - $this->global_prefix = ''; - $this->blog_prefix = ''; + $this->__set( 'global_prefix', '' ); + $this->__set( 'blog_prefix', '' ); if ( function_exists( 'is_multisite' ) ) { $this->global_prefix = ( is_multisite() || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix; @@ -1114,8 +1114,8 @@ function __construct() { $this->salt_keys( WP_CACHE_KEY_SALT ); - $this->cache_hits =& $this->stats['get']; - $this->cache_misses =& $this->stats['add']; + $this->__set( 'cache_hits', $this->stats['get'] ); + $this->__set( 'cache_misses', $this->stats['add'] ); } function increment_stat( $field, $num = 1 ) { @@ -1181,7 +1181,7 @@ function strip_memcached_keys( $keys ) { } function timer_start() { - $this->time_start = microtime( true ); + $this->__set( 'time_start', microtime( true ) ); return true; } From c200707bfdbd543b6616def6295cf2f38300e23b Mon Sep 17 00:00:00 2001 From: Philip John Date: Tue, 31 Oct 2023 12:11:56 +0000 Subject: [PATCH 2/4] PHP 8.2: Define properties instead of using __set() magic method --- object-cache.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/object-cache.php b/object-cache.php index 3c6d02d..52fd911 100644 --- a/object-cache.php +++ b/object-cache.php @@ -197,6 +197,13 @@ class WP_Object_Cache { var $size_total = 0; var $slow_op_microseconds = 0.005; // 5 ms + var $global_prefix = ''; + var $blog_prefix = ''; + var $key_salt = ''; + var $cache_hits = 0; + var $cache_misses = 0; + var $time_start = 0; + function add( $id, $data, $group = 'default', $expire = 0 ) { $key = $this->key( $id, $group ); @@ -1036,9 +1043,9 @@ function failure_callback( $host, $port ) { function salt_keys( $key_salt ) { if ( strlen( $key_salt ) ) { - $this->__set( 'key_salt', $key_salt . ':' ); + $this->key_salt = $key_salt . ':'; } else { - $this->__set( 'key_salt', '' ); + $this->key_salt = ''; } } @@ -1104,8 +1111,8 @@ function __construct() { global $blog_id, $table_prefix; - $this->__set( 'global_prefix', '' ); - $this->__set( 'blog_prefix', '' ); + $this->global_prefix = ''; + $this->blog_prefix = ''; if ( function_exists( 'is_multisite' ) ) { $this->global_prefix = ( is_multisite() || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix; @@ -1114,8 +1121,8 @@ function __construct() { $this->salt_keys( WP_CACHE_KEY_SALT ); - $this->__set( 'cache_hits', $this->stats['get'] ); - $this->__set( 'cache_misses', $this->stats['add'] ); + $this->cache_hits = $this->stats['get']; + $this->cache_misses = $this->stats['add']; } function increment_stat( $field, $num = 1 ) { @@ -1181,7 +1188,7 @@ function strip_memcached_keys( $keys ) { } function timer_start() { - $this->__set( 'time_start', microtime( true ) ); + $this->time_start = microtime( true ); return true; } From 91f336ff16cb7fad5560b3972509362210789a86 Mon Sep 17 00:00:00 2001 From: Philip John Date: Tue, 31 Oct 2023 12:12:45 +0000 Subject: [PATCH 3/4] PHP 8.2: Restore assignement by reference --- object-cache.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/object-cache.php b/object-cache.php index 52fd911..c5e1a0e 100644 --- a/object-cache.php +++ b/object-cache.php @@ -1121,8 +1121,8 @@ function __construct() { $this->salt_keys( WP_CACHE_KEY_SALT ); - $this->cache_hits = $this->stats['get']; - $this->cache_misses = $this->stats['add']; + $this->cache_hits =& $this->stats['get']; + $this->cache_misses =& $this->stats['add']; } function increment_stat( $field, $num = 1 ) { From c0cb106a9b28f91168e9f00c7f30ffd129fd9909 Mon Sep 17 00:00:00 2001 From: Philip John Date: Tue, 31 Oct 2023 12:13:13 +0000 Subject: [PATCH 4/4] PHP 8.2: Fix spacing --- object-cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/object-cache.php b/object-cache.php index c5e1a0e..08ef807 100644 --- a/object-cache.php +++ b/object-cache.php @@ -1112,7 +1112,7 @@ function __construct() { global $blog_id, $table_prefix; $this->global_prefix = ''; - $this->blog_prefix = ''; + $this->blog_prefix = ''; if ( function_exists( 'is_multisite' ) ) { $this->global_prefix = ( is_multisite() || defined( 'CUSTOM_USER_TABLE' ) && defined( 'CUSTOM_USER_META_TABLE' ) ) ? '' : $table_prefix;