Skip to content

Fix php 7.4 regression on strtolower to false on ClassLikeNameClassNameImportSkipVoter#7436

Merged
samsonasik merged 2 commits intomainfrom
fix-php74-strtolower
Oct 6, 2025
Merged

Fix php 7.4 regression on strtolower to false on ClassLikeNameClassNameImportSkipVoter#7436
samsonasik merged 2 commits intomainfrom
fix-php74-strtolower

Conversation

@samsonasik
Copy link
Member

@samsonasik samsonasik enabled auto-merge (squash) October 6, 2025 20:27
@samsonasik samsonasik merged commit 24b76ca into main Oct 6, 2025
49 of 50 checks passed
@samsonasik samsonasik deleted the fix-php74-strtolower branch October 6, 2025 20:29
$shortNameLowered = $fullyQualifiedObjectType->getShortNameLowered();
$fullyQualifiedObjectTypeNamespace = strtolower(
substr($fullyQualifiedObjectType->getClassName(), 0, -strlen($fullyQualifiedObjectType->getShortName()) - 1)
substr($fullyQualifiedObjectType->getClassName(), 0, -strlen($fullyQualifiedObjectType->getShortName()) - 1) ?: ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a note about PHP 7.4? So we don't accidentally remove it :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I created new PR to add note for it

the RecastingRemovalRector needs also improvement for it, currently skipped

rector-src/rector.php

Lines 57 to 60 in 21b6091

// todo: properly handle, substr() can return false on php 7.x
RecastingRemovalRector::class => [
__DIR__ . '/rules/CodingStyle/ClassNameImport/ClassNameImportSkipVoter/ClassLikeNameClassNameImportSkipVoter.php',
],

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this problem is not patched by PHPStan. is it reproducible on the phpstan playground, that we are missing a error here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems on phpstan.org, it shows

on php 8.0+, show empy string
on php 7.2+, show false

see https://phpstan.org/r/6c0960c9-23d9-4387-8f95-f13f2f50f33b

Copy link
Contributor

@clxmstaab clxmstaab Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh I just see rector-src does not run PHPStan on PHP7.x.. you are only using a single PHP 8.2 job and therefore miss PHPStan errors on all other PHP versions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created PR to skip remove (string) case on substr() on RecastingRemovalRector on getNativeType() method:

$shortNameLowered = $fullyQualifiedObjectType->getShortNameLowered();
$fullyQualifiedObjectTypeNamespace = strtolower(
substr($fullyQualifiedObjectType->getClassName(), 0, -strlen($fullyQualifiedObjectType->getShortName()) - 1)
substr($fullyQualifiedObjectType->getClassName(), 0, -strlen($fullyQualifiedObjectType->getShortName()) - 1) ?: ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be also good candidate for a downgrade rule

@samsonasik
Copy link
Member Author

@TomasVotruba I need to create immediate release 2.2.1 for it :)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System error: "strtolower() expects parameter 1 to be string, bool given

3 participants