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

Fatal error: Uncaught TypeError: explode() in class-wp-dependencies.php:187 #84

Open
bobbingwide opened this issue Oct 30, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@bobbingwide
Copy link
Owner

Today, while updating the block docs for WordPress 6.1 I got a Fatal error when attempting to edit https://blocks.wp.a2z/block/no-results-core-query-no-results/

Gutenberg version: 14.1.1.
Latest version of Gutenberg is 14.4.0


Warning: Array to string conversion in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php on line 76

Warning: Array to string conversion in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php on line 76

Fatal error: Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, array given in C:\apache\htdocs\wp-a2z\wp-includes\class-wp-dependencies.php:187
Stack trace:
#0 C:\apache\htdocs\wp-a2z\wp-includes\class-wp-dependencies.php(187): explode('?', Array)
#1 C:\apache\htdocs\wp-a2z\wp-includes\class-wp-styles.php(371): WP_Dependencies->all_deps(Array, false, false)
#2 C:\apache\htdocs\wp-a2z\wp-includes\class-wp-dependencies.php(127): WP_Styles->all_deps(Array)
#3 C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php(83): WP_Dependencies->do_items(Array)
#4 C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php(109): gutenberg_resolve_assets()
#5 C:\apache\htdocs\wp-a2z\wp-includes\class-wp-hook.php(310): {closure}(Array)
#6 C:\apache\htdocs\wp-a2z\wp-includes\plugin.php(205): WP_Hook->apply_filters(Array, Array)
#7 C:\apache\htdocs\wp-a2z\wp-includes\block-editor.php(539): apply_filters('block_editor_se...', Array, Object(WP_Block_Editor_Context))
#8 C:\apache\htdocs\wp-a2z\wp-admin\edit-form-blocks.php(284): get_block_editor_settings(Array, Object(WP_Block_Editor_Context))
#9 C:\apache\htdocs\wp-a2z\wp-admin\post.php(187): require('C:\\apache\\htdoc...')
#10 {main}
  thrown in <b>C:\apache\htdocs\wp-a2z\wp-includes\class-wp-dependencies.php</b> on line <b>187</b><br />
@bobbingwide
Copy link
Owner Author

bobbingwide commented Oct 30, 2022

Updating to Gutenberg 14.4.0 seemed to resolve the issue.
It still crashed with: 14.3.1, 14.3.0 and 14.2.0
Which might be a bit of a shame since WordPress 6.1 includes Gutenberg 14.1

@bobbingwide
Copy link
Owner Author

I retested after updating to WordPress 6.1-RC5.
I still get the errors with Gutenberg 14.3.1 and earlier

Gutenberg version Result
14.4.0 works
14.3.1 fails as above
14.3.0 fails as above
14.2.0 fails as above
14.1.1 fails as above

@bobbingwide bobbingwide added the bug Something isn't working label Oct 31, 2022
@bobbingwide
Copy link
Owner Author

bobbingwide commented Oct 31, 2022

The stack trace for the first warning

C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php(286:2) bw_trace_error_handler(1) 219 24 2022-10-31T21:19:52+00:00 2.758449 0.023853 cf=block_editor_settings_all 76280 168 10266 18874368/18874368 512M F=1303 err Array

[0] => (integer) 2
[1] => (string) "Warning: Array to string conversion"
[2] => (string) "C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php"
[3] => (integer) 76
0. bw_lazy_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\libs\bwtrace.php:108 0
1. bw_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php:293 0
2. bw_trace_error_handler(2,Array to string conversion,C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php,76) C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\includes\bwtrace-actions.php:0 4
3. array_unique(array) C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php:76 1
4. gutenberg_resolve_assets C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\compat\wordpress-6.0\client-assets.php:109 0
5. {closure}(array) C:\apache\htdocs\wp-a2z\wp-includes\class-wp-hook.php:310 1
6. apply_filters(array,array) C:\apache\htdocs\wp-a2z\wp-includes\plugin.php:205 2
7. apply_filters(block_editor_settings_all,array,object) C:\apache\htdocs\wp-a2z\wp-includes\block-editor.php:539 3
8. get_block_editor_settings(array,object) C:\apache\htdocs\wp-a2z\wp-admin\edit-form-blocks.php:284 2
9. require(C:\apache\htdocs\wp-a2z\wp-admin\edit-form-blocks.php) C:\apache\htdocs\wp-a2z\wp-admin\post.php:187 1

is most likely related to the fact that the style_handles array is not flat, with two entries which are themselves arrays.

  [151] => Array

        [0] => (string) "wp-block-post-comments-form"
        [1] => (string) "wp-block-buttons"
        [2] => (string) "wp-block-button"

and

 [228] => Array

        [0] => (string) "wp-block-post-comments"
        [1] => (string) "wp-block-buttons"
        [2] => (string) "wp-block-button"

In WP 6.1-RC5 if _wp_get_iframed_editor_assets() exists then the filter function for block_editor_settings_all just returns the $settings.

In WP 6.1-RC3 it called gutenberg_resolve_assets(), which produced the Warnings.

I believe I've found the original issue. WordPress/gutenberg#45301

@bobbingwide
Copy link
Owner Author

_wp_get_iframed_editor_assets() uses different logic to gutenberg_resolve_assets() to build $style_handles and $script_handles

foreach ( $block_registry->get_all_registered() as $block_type ) {
		$style_handles = array_merge(
			$style_handles,
			$block_type->style_handles,
			$block_type->editor_style_handles
		);

		$script_handles = array_merge(
			$script_handles,
			$block_type->script_handles
		);
	}

compared with the logic in gutenberg_resolve_assets(), which doesn't use array_merge().

foreach ( $block_registry->get_all_registered() as $block_type ) {
		if ( ! empty( $block_type->style ) ) {
			$style_handles[] = $block_type->style;
		}

		if ( ! empty( $block_type->editor_style ) ) {
			$style_handles[] = $block_type->editor_style;
		}

		if ( ! empty( $block_type->script ) ) {
			$script_handles[] = $block_type->script;
		}
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant