Fatal error when pasting snippets with <?php
-
Hi WPCode team,
First of all, thank you for this great plugin. I’ve been using it to manage my code snippets and it’s been very helpful.I wanted to report an issue I encountered when pasting a snippet that starts with
<?php declare( strict_types=1 );. When I saved and activated the snippet, it generated a fatal error:strict_types declaration must be the very first statement in the script.The problem is that WPCode (or any snippet manager plugin) already handles the PHP opening tag and execution context, so including <?php declare( strict_types=1 ); in the snippet creates a conflict.
Here’s what happened:
- A plugin support agent suggested to add this snippet to disable their Site Health integration:
<?php declare( strict_types=1 );
add_filter( 'shield/can_run_site_health_security', '__return_false' );- I pasted it into WPCode and saved/activated it
- This caused a fatal error that broke my site
- Even worse, while this issue was presen WPCode was reporting other snippets as broken when they were actually working fine (probably because the error corrupted the snippet validation state).
- Once i removed the real corrupted snippet I was able to reactivate other snippet marked as broken for error by your plugin workflow.
Suggestion:
It would be great if WPCode could automatically detect when a pasted snippet starts with <?php declare( strict_types=1 ); and either:- Strip it automatically before saving
- Show a warning to the user explaining that this declaration is not needed in snippet managers
- Handle it gracefully to prevent fatal errors
This is important because many plugin developers provide complete code snippets (with the PHP opening tag and declarations) in their documentation, and users like me often copy-paste them directly without realizing they need to be modified for snippet managers.
Thanks for considering this improvement!
You must be logged in to reply to this topic.