php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77789 Undocumented E_WARNINGs raised in invalid regexps
Submitted: 2019-03-24 11:00 UTC Modified: -
From: beebware at gmail dot com Assigned:
Status: Open Package: *Regular Expressions
PHP Version: 7.3.3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
39 + 48 = ?
Subscribe to this entry?

 
 [2019-03-24 11:00 UTC] beebware at gmail dot com
Description:
------------
---
From manual page: https://php.net/function.preg-replace
---

The documentation states:
```
Errors/Exceptions ΒΆ
As of PHP 5.5.0 E_DEPRECATED level error is emitted when passing in the "\e" modifier. As of PHP 7.0.0 E_WARNING is emitted in this case and "\e" modifier has no effect.
```


However, E_WARNING s are raised if the regular expression is invalid.

I feel that just adding a comment in the 'Errors/Exceptions' part of the documentation that 'E_WARNINGs will be raised if an error occurs. NULL will will be returned and preg_last_error will be populated.' will suffice, but ideally (and this would probably require a code change) a way of stopping the E_WARNINGSs being emitted would be the 'best solution'.

Test script:
---------------
https://3v4l.org/ULXiT

<?php

var_dump(preg_replace('/aodjsoidjas','','tester'));

Expected result:
----------------
No E_WARNING raised, but NULL to be returned and preg_last_error to be populated.

Actual result:
--------------
E_WARNING is raised (not documented), but NULL to be returned and preg_last_error to be populated.

```
Warning: preg_replace(): No ending delimiter '/' found in /in/ULXiT on line 3
NULL
```

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 13 05:01:26 2019 UTC