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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: beebware at gmail dot com
New email:
PHP Version: OS:

 

 [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: Mon Nov 18 23:01:35 2019 UTC