Skip to content

Commit 471edb0

Browse files
Code Modernization: Silence the deprecation warnings for missing return type in WP_Hook.
This fixes the "Deprecated: Return type of `WP_Hook::[METHODNAME]()` should be compatible with `ArrayAccess::[METHODNAME](): type`" warnings on PHP 8.1. PHP native interfaces now have declared return types and methods in classes implementing these interfaces need to either have the return type declared (in a covariant compatible manner with the PHP native interface method declaration), or need to silence the deprecation warning using the `#[ReturnTypeWillChange]` attribute. Follow-up to [51517], [51529]. Props jrf. See #53635. git-svn-id: https://develop.svn.wordpress.org/trunk@51530 602fd350-edb4-49c9-b593-d223f7449a82
1 parent df724f9 commit 471edb0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/wp-includes/class-wp-hook.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ public static function build_preinitialized_hooks( $filters ) {
437437
* @param mixed $offset An offset to check for.
438438
* @return bool True if the offset exists, false otherwise.
439439
*/
440+
#[ReturnTypeWillChange]
440441
public function offsetExists( $offset ) {
441442
return isset( $this->callbacks[ $offset ] );
442443
}
@@ -451,6 +452,7 @@ public function offsetExists( $offset ) {
451452
* @param mixed $offset The offset to retrieve.
452453
* @return mixed If set, the value at the specified offset, null otherwise.
453454
*/
455+
#[ReturnTypeWillChange]
454456
public function offsetGet( $offset ) {
455457
return isset( $this->callbacks[ $offset ] ) ? $this->callbacks[ $offset ] : null;
456458
}
@@ -465,6 +467,7 @@ public function offsetGet( $offset ) {
465467
* @param mixed $offset The offset to assign the value to.
466468
* @param mixed $value The value to set.
467469
*/
470+
#[ReturnTypeWillChange]
468471
public function offsetSet( $offset, $value ) {
469472
if ( is_null( $offset ) ) {
470473
$this->callbacks[] = $value;
@@ -482,6 +485,7 @@ public function offsetSet( $offset, $value ) {
482485
*
483486
* @param mixed $offset The offset to unset.
484487
*/
488+
#[ReturnTypeWillChange]
485489
public function offsetUnset( $offset ) {
486490
unset( $this->callbacks[ $offset ] );
487491
}
@@ -495,6 +499,7 @@ public function offsetUnset( $offset ) {
495499
*
496500
* @return array Of callbacks at current priority.
497501
*/
502+
#[ReturnTypeWillChange]
498503
public function current() {
499504
return current( $this->callbacks );
500505
}
@@ -508,6 +513,7 @@ public function current() {
508513
*
509514
* @return array Of callbacks at next priority.
510515
*/
516+
#[ReturnTypeWillChange]
511517
public function next() {
512518
return next( $this->callbacks );
513519
}
@@ -521,6 +527,7 @@ public function next() {
521527
*
522528
* @return mixed Returns current priority on success, or NULL on failure
523529
*/
530+
#[ReturnTypeWillChange]
524531
public function key() {
525532
return key( $this->callbacks );
526533
}
@@ -534,6 +541,7 @@ public function key() {
534541
*
535542
* @return bool Whether the current position is valid.
536543
*/
544+
#[ReturnTypeWillChange]
537545
public function valid() {
538546
return key( $this->callbacks ) !== null;
539547
}
@@ -545,6 +553,7 @@ public function valid() {
545553
*
546554
* @link https://www.php.net/manual/en/iterator.rewind.php
547555
*/
556+
#[ReturnTypeWillChange]
548557
public function rewind() {
549558
reset( $this->callbacks );
550559
}

0 commit comments

Comments
 (0)