godaddy-wordpress / godaddy-wordpress/coblocks

PHP 8.x warning: pass-by-reference parameter in block-migrate/loader.php closure

Open
#2,662 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
794
Forks
142
PR merge metrics
No merged PRs in 30d

Description

## Description

The `the_post` callback in `includes/block-migrate/loader.php:29` declares its parameter as pass-by-reference:

```php
function( WP_Post &$post ) {
```

WordPress's `WP_Hook::apply_filters()` passes arguments by value, so this generates a warning on every page load under PHP 8.x:

```
PHP Warning: CoBlocks::{closure}(): Argument #1 ($post) must be passed by reference, value given in wp-includes/class-wp-hook.php on line 343
```

## Steps to Reproduce

1. Activate CoBlocks on PHP 8.x
2. Visit any post/page on the frontend
3. Check the error log

## Fix

Remove the `&` from the closure parameter. Since `WP_Post` is an object, it's already passed by handle — the reference is unnecessary.

```diff
- function( WP_Post &$post ) {
+ function( WP_Post $post ) {
```

## Environment

- CoBlocks 3.1.17
- PHP 8.3
- WordPress 6.7

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.