Skip to content
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

Error level changed in preg_match and preg_match_all functions #1595

Closed
NVoronina opened this issue May 25, 2022 · 3 comments
Closed

Error level changed in preg_match and preg_match_all functions #1595

NVoronina opened this issue May 25, 2022 · 3 comments

Comments

@NVoronina
Copy link

Error changed if you use not a string as second argument in preg_match function from E_WARNING before 8.0 to TypeError in 8+ versions.
Code example:
<?php $var = preg_match('#[0-9]#', ['test']); var_dump($var);

Result 7.4:
Warning: preg_match() expects parameter 2 to be string, array given in /home/user/scripts/code.php on line 3
bool(false)

Result 8.0:
Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in /home/user/scripts/code.php:3

PS preg_match_all the same behavior

@kamil-tekiela
Copy link
Member

Array was never a valid argument to these functions. PHP 8.0 is now throwing an error when an undefined behaviour is triggered by providing invalid parameter values. It's got nothing to do with PCRE functions.

@cmb69
Copy link
Contributor

cmb69 commented May 25, 2022

See also https://www.php.net/manual/en/functions.internal.php

@NVoronina
Copy link
Author

See also https://www.php.net/manual/en/functions.internal.php

Thanks, I just ask for this in docs. But now I see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants