Skip to content

Commit ab3b9d1

Browse files
authored
Merge pull request #190 from wp-cli/fix/186
Fix deprecation warnings on PHP 8.2
2 parents df98093 + 04c9da6 commit ab3b9d1

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/Logger.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44

55
class Logger {
66

7-
public $time = 0;
8-
public $query_count = 0;
9-
public $query_time = 0;
10-
public $cache_hits = 0;
11-
public $cache_misses = 0;
12-
public $cache_ratio = null;
13-
public $hook_count = 0;
14-
public $hook_time = 0;
15-
public $request_count = 0;
16-
public $request_time = 0;
17-
public $callback_count = 0;
18-
7+
public $time = 0;
8+
public $query_count = 0;
9+
public $query_time = 0;
10+
public $cache_hits = 0;
11+
public $cache_misses = 0;
12+
public $cache_ratio = null;
13+
public $hook_count = 0;
14+
public $hook_time = 0;
15+
public $request_count = 0;
16+
public $request_time = 0;
1917
private $start_time = null;
2018
private $query_offset = null;
2119
private $cache_hit_offset = null;
@@ -24,12 +22,30 @@ class Logger {
2422
private $hook_depth = 0;
2523
private $request_start_time = null;
2624

25+
private $definitions = array();
26+
2727
public static $active_loggers = array();
2828

2929
public function __construct( $definition = array() ) {
3030
foreach ( $definition as $k => $v ) {
31-
$this->$k = $v;
31+
$this->definitions[ $k ] = $v;
32+
}
33+
}
34+
35+
public function __get( $key ) {
36+
if ( isset( $this->definitions[ $key ] ) ) {
37+
return $this->definitions[ $key ];
3238
}
39+
40+
return null;
41+
}
42+
43+
public function __set( $key, $value ) {
44+
$this->definitions[ $key ] = $value;
45+
}
46+
47+
public function __isset( $key ) {
48+
return isset( $this->definitions[ $key ] );
3349
}
3450

3551
/**

src/Profiler.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ function () {
9999
}
100100
}
101101
);
102-
if ( 'hook' === $this->type
103-
&& ':before' === substr( $this->focus, -7, 7 ) ) {
102+
if (
103+
'hook' === $this->type &&
104+
$this->focus &&
105+
':before' === substr( $this->focus, -7, 7 )
106+
) {
104107
$stage_hooks = array();
105108
foreach ( $this->stage_hooks as $hooks ) {
106109
$stage_hooks = array_merge( $stage_hooks, $hooks );
@@ -114,8 +117,11 @@ function () {
114117
WP_CLI::add_hook( 'after_wp_config_load', array( $this, 'wp_tick_profile_begin' ) );
115118
}
116119
WP_CLI::add_wp_hook( $end_hook, array( $this, 'wp_tick_profile_end' ), -9999 );
117-
} elseif ( 'hook' === $this->type
118-
&& ':after' === substr( $this->focus, -6, 6 ) ) {
120+
} elseif (
121+
'hook' === $this->type &&
122+
$this->focus &&
123+
':after' === substr( $this->focus, -6, 6 )
124+
) {
119125
$start_hook = substr( $this->focus, 0, -6 );
120126
WP_CLI::add_wp_hook( $start_hook, array( $this, 'wp_tick_profile_begin' ), 9999 );
121127
} else {

0 commit comments

Comments
 (0)