Skip to content

Improve preg_* functions warnings for NUL byte #13068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 7, 2024

Conversation

jorgsowa
Copy link
Contributor

@jorgsowa jorgsowa commented Jan 3, 2024

I thought that replacing NUL to NUL byte brings more clarity what we expect as delimiter in preg_* functions.

It can be replaced with null character, null terminator, or maybe with explicit NUL (\0), but simple NUL can be mistaken with the null in PHP language. I was also confused when I was seeing this message for the first time.

Additionally I formatted code of tests which were affected by this change.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me

'/[a-zA-Z]/', //Regex string
];
$array = [123, 'abc', 'test'];
foreach ($values as $value) {
@print "\nArg value is $value\n";
Copy link
Member

Choose a reason for hiding this comment

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

Why is the print call suppressed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise we get Warning: Array to string conversion in. What do you think about removing this print, as this is not really necessary?

Copy link
Member

Choose a reason for hiding this comment

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

Oh it's because of that nested array... I mean this will break in PHP 9 when we promote this sooooooo, removing it is probably fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for review. I removed unnecessary strings from those tests such:

  • header of a test printed
  • value print
  • Done string at the end of test

$subject = 'test';
foreach($regex_array as $regex_value) {
foreach ($regex_array as $regex_value) {
@print "\nArg value is $regex_value\n";
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

$subject = 'this is a test';
foreach($regex_array as $regex_value) {
foreach ($regex_array as $regex_value) {
@print "\nArg value is $regex_value\n";
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

function integer_word($matches) {
global $replacement;
return $replacement[$matches[0]];
}
$subject = 'number 1.';
foreach($regex_array as $regex_value) {
foreach ($regex_array as $regex_value) {
@print "\nArg value is $regex_value\n";
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

$replace = 1;
$subject = 'a';
foreach($regex_array as $regex_value) {
foreach ($regex_array as $regex_value) {
@print "\nArg value is $regex_value\n";
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

$subject = '1 2 a 3 4 b 5 6';
foreach($regex_array as $regex_value) {
foreach ($regex_array as $regex_value) {
@print "\nArg value is $regex_value\n";
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@@ -6,11 +6,9 @@ Test preg_match() function : error conditions - wrong arg types
/*
* Testing how preg_match reacts to being passed the wrong type of subject argument
*/
Copy link
Member

Choose a reason for hiding this comment

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

This test seems to be a ZPP test, and should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -8,28 +8,21 @@ Test preg_match_all() function : error conditions - wrong arg types
/*
Copy link
Member

Choose a reason for hiding this comment

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

This test also looks like a ZPP test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Girgias Girgias merged commit 73722df into php:master Jan 7, 2024
@jorgsowa jorgsowa deleted the fix-preg-match-nul-warning-message branch February 8, 2024 22:11
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.

2 participants