Skip to content

Add preg_last_error_msg() function #5185

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

Closed
wants to merge 12 commits into from

Conversation

nicoSWD
Copy link

@nicoSWD nicoSWD commented Feb 17, 2020

This PR adds a new PCRE function called preg_last_error_msg which returns a human-friendly string representation of the last error.

Seeing as most comments in the preg_last_error() documentation are about converting the error codes to meaningful messages, I see no reason why this shouldn't be supported natively.

The JSON extension also provides two separate functions for both use-cases.

And so do many others, such as

etc...

So to me it feels natural for this function to exist. The naming scheme seems faily inconsistent, but I like the _msg suffix the most.

Thoughts? And does this need an RFC?

Edit:
For reference, here's the PHP internals discussion:
https://externals.io/message/108665

@nikic nikic added the Feature label Feb 17, 2020
@nikic
Copy link
Member

nikic commented Feb 17, 2020

Sounds reasonable. I'd suggest sending a mail to the internals mailing list about this. If the addition is not controversial, then we can add it without a full RFC.

@nicoSWD
Copy link
Author

nicoSWD commented Feb 18, 2020

Sounds reasonable. I'd suggest sending a mail to the internals mailing list about this. If the addition is not controversial, then we can add it without a full RFC.

Thank you! I'll do that!

@danon
Copy link

danon commented Feb 20, 2020

Perhaps you didn't know, there's a wrapper library for regexps in PHP, and it already has preg_last_error_msg(), if you'd like to use it: https://t-regx.com/docs/utils.

@nicoSWD
Copy link
Author

nicoSWD commented Feb 24, 2020

@nikic Looks like there weren't any objections or concerns regarding this. Is there anything else I should do?

@php-pulls php-pulls closed this in aa79a22 Feb 25, 2020
@nicoSWD
Copy link
Author

nicoSWD commented Feb 25, 2020

Thank you, @nikic! Will this be part of PHP 8, or an earlier release?

@nikic
Copy link
Member

nikic commented Feb 25, 2020

@nicoSWD This will be part of PHP 8.0.

nicolas-grekas added a commit to symfony/polyfill that referenced this pull request Feb 27, 2020
This PR was squashed before being merged into the 1.14-dev branch.

Discussion
----------

[PHP 8.0] Add preg_last_error_msg function

This PR adds the function `preg_last_error_msg` added in [php-src/pull/5185](php/php-src#5185)

_Note_: I only tested the cases that don't require special `.ini` settings as I didn't want to set them dynamically in the test suite.

Commits
-------

151806f [PHP 8.0] Add preg_last_error_msg function
@carusogabriel carusogabriel added this to the PHP 8.0 milestone May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants