Problem/Motivation
The Rocketship Blocks module is using the deprecated PHP substr() function with a potential null parameter in rocketship_blocks_title_preprocess_block(). This generates deprecation notices in PHP 8.1+ and could lead to runtime errors in future PHP versions. The issue needs to be addressed to ensure compatibility with newer PHP versions and maintain code quality.
Steps to reproduce
- Install the Rocketship Core module and enable Rocketship Blocks submodule
- Enable deprecation notices in your PHP configuration
- Navigate to a page where rocketship_blocks_title_preprocess_block() is called
- Check the logs or screen for the deprecation notice:
Deprecated function: substr(): Passing null to parameter #1 ($string) of type string is deprecated in rocketship_blocks_title_preprocess_block() (line 229 of modules/contrib/rocketship_core/modules/rocketship_blocks/rocketship_blocks.module)
Proposed resolution
Replace the deprecated substr() function with str_starts_with(), which is more appropriate for prefix checking and handles null values better. This function was introduced in PHP 8.0 and is the recommended way to check string prefixes.
Remaining tasks
- Create a patch replacing substr() with str_starts_with()
- Add appropriate null checking if necessary
- Test the changes to ensure functionality remains the same
- Update module documentation if needed
User interface changes
None. This is a code-level change that doesn't affect the user interface.
API changes
None. This is an internal function modification that doesn't affect the module's API.
Data model changes
None. This change only affects code functionality and doesn't modify any data structures or storage.
Issue fork rocketship_core-3508107
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
jorgik commentedComment #5
nginex commentedThat's not a solution. Now I can see
Deprecated function: str_starts_with(): Passing null to parameter #1 ($haystack) of type string is deprecated in _rocketship_blocks_title_preprocess_block()
Let me provide a correct solution
Comment #6
nginex commentedPushed correct fix, the error is gone.
Comment #10
l_vandamme commentedCommitted on 6.2.x and released as part of https://www.drupal.org/project/rocketship_core/releases/6.2.4
Comment #12
l_vandamme commented