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

  1. Install the Rocketship Core module and enable Rocketship Blocks submodule
  2. Enable deprecation notices in your PHP configuration
  3. Navigate to a page where rocketship_blocks_title_preprocess_block() is called
  4. 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

  1. Create a patch replacing substr() with str_starts_with()
  2. Add appropriate null checking if necessary
  3. Test the changes to ensure functionality remains the same
  4. 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.

Command icon 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

jorgik created an issue. See original summary.

jorgik changed the visibility of the branch 3508107-deprecation-notice-in to hidden.

jorgik’s picture

Status: Active » Needs review
nginex’s picture

Assigned: Unassigned » nginex
Status: Needs review » Needs work

That'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

nginex’s picture

Assigned: nginex » Unassigned
Status: Needs work » Reviewed & tested by the community

Pushed correct fix, the error is gone.

  • ed7a37f1 committed on 6.2.x
    fix: #3508107 Deprecation notice in...

  • nginex committed b3f8a763 on 6.2.x
    Issue #3508107: Ensure the subtitle value is not null
    

  • jorgik committed 111f7c68 on 6.2.x
    Issue #3508107: Deprecation notice in...
l_vandamme’s picture

Status: Reviewed & tested by the community » Fixed

Committed on 6.2.x and released as part of https://www.drupal.org/project/rocketship_core/releases/6.2.4

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

l_vandamme’s picture

Status: Fixed » Closed (fixed)