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: 2021-07-26 13:58 UTC
From: beebware at gmail dot com Assigned:
Status: Verified Package: *Regular Expressions
PHP Version: 7.3.3 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-26 13:58 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2021-07-26 13:58 UTC] cmb@php.net
Right, that should be documented, although I'd consider passing an
invalid regex to these function a programming error.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC