Skip to content

Fix test to use non-interned string - #25370

Closed
rr-it wants to merge 1 commit into
php:PHP-8.6from
rr-it:fix/testcase-non-interned-string
Closed

rr-it wants to merge 1 commit into
php:PHP-8.6from
rr-it:fix/testcase-non-interned-string

Conversation

@rr-it

@rr-it rr-it commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This changes the test-case to actually use a non-interned string.

This construct actually becomes an interned string after optimizations applied in 93fd714:

$str = str_repeat("my valid string", random_int(1, 1));

php-src/ext/standard/string.c

Lines 5641 to 5643 in 93fd714

if (mult == 1) {
RETURN_STR_COPY(input_str);
}


Further random_int(1, 1) is optimized since PHP 7:

if (min == max) {
RETURN_LONG(min);
}

Implemented with c12917a and further refactored with b14dd85 and 4d8dd8d.

@ndossche

Copy link
Copy Markdown
Member

Wrong commit pointed, str_repeat got optimized such that passing 1 returns the input string, that's the root cause not the ext/random changes.
Your alternative doesn't work because of SCCP.
Also, many tests rely on the old str_repeat+random_int trick. The simplest fix is likely to change the randomness bounds to 2,2

@rr-it

rr-it commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

The simplest fix is likely to change the randomness bounds to 2,2

@ndossche That one fixes it. Do you add a new PR or shall I?


Your alternative doesn't work because of SCCP.

This alternative actually works to create non-interned strings:

$strInterned = "my valid";
$strNonInterned = $strInterned . " string";

Also see:
#25371

@rr-it
rr-it force-pushed the fix/testcase-non-interned-string branch 2 times, most recently from e468c25 to 4fedde6 Compare November 10, 2026 14:22
@ndossche

Copy link
Copy Markdown
Member

This made it into 8.6, so the target branch should be PHP-8.6. You may do the fixes in this PR.

@rr-it
rr-it force-pushed the fix/testcase-non-interned-string branch from 4fedde6 to b31b3bc Compare November 10, 2026 19:14
@rr-it
rr-it changed the base branch from master to PHP-8.6 November 10, 2026 19:15
@rr-it

rr-it commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Commit rebased on branch PHP-8.6 and PR changed to target branch PHP-8.6.

@LamentXU123 LamentXU123 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thx! LGTM otherwise you remove the unrelated change below.

@rr-it

rr-it commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

remove the unrelated change below.

@LamentXU123 Sorry, I do not get the point. Please tell again.

The line itself is not unrelated, as this change doubles the string now.

@LamentXU123

LamentXU123 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Oh I see. My bad, was a bit sick today. I mixed up the diff from another PR
Then it looks fine. I will merge it, thanks a lot.

LamentXU123 added a commit that referenced this pull request Nov 13, 2026
* PHP-8.6:
  Fix test to use non-interned string (#25370)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants