php / php/php-src

preg_match and preg_match_all both do not set $matches on regex fail, leaving as it was set prior to call

Abierto
#7,917 6 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Extension: pcre Feature Status: Verified
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.1k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

Description

The following code:

<?php // preg_match_all.php
$matches = [0 => 'Orange',
            1 => 'Apple',
            2 => 'Banana',
            3 => 'Monkey'];
$result = preg_match_all('aeiou{0,', 'ou', $matches);
var_dump($result);
var_dump($matches);

$result = preg_match('aeiou{0,', 'ou', $matches);
var_dump($result);
var_dump($matches);

Resulted in this output from command line %php preg_match_all.php:

PHP Warning:  preg_match_all(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 6
PHP Stack trace:
PHP   1. {main}() preg_match_all.php:0
PHP   2. preg_match_all($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:6
preg_match_all.php:7:
bool(false)
preg_match_all.php:8:
array(4) {
    [0] =>
  string(6) "Orange"
    [1] =>
  string(5) "Apple"
    [2] =>
  string(6) "Banana"
    [3] =>
  string(6) "Monkey"
}
PHP Warning:  preg_match(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 10
PHP Stack trace:
PHP   1. {main}() preg_match_all.php:0
PHP   2. preg_match($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:10
preg_match_all.php:11:
bool(false)
preg_match_all.php:12:
array(4) {
    [0] =>
  string(6) "Orange"
    [1] =>
  string(5) "Apple"
    [2] =>
  string(6) "Banana"
    [3] =>
  string(6) "Monkey"
}

But I expected this output instead:

PHP Warning:  preg_match_all(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 6
PHP Stack trace:
PHP   1. {main}() preg_match_all.php:0
PHP   2. preg_match_all($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:6
preg_match_all.php:7:
bool(false)
preg_match_all.php:8:
either: null or array[0]
PHP Warning:  preg_match(): Delimiter must not be alphanumeric or backslash in preg_match_all.php on line 10
PHP Stack trace:
PHP   1. {main}() preg_match_all.php:0
PHP   2. preg_match($pattern = 'aeiou{0,', $subject = 'ou', $subpatterns = [0 => 'Orange', 1 => 'Apple', 2 => 'Banana', 3 => 'Monkey']) preg_match_all.php:10
preg_match_all.php:11:
bool(false)
preg_match_all.php:12:
either: null or array[0]
PHP Version

PHP 7.4.27

Operating System

No response

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce las llamadas proporcionadas a preg_match() y preg_match_all() con el patrón no válido en PHP 7.4.27 y, a continuación, rastrea las dos APIs en el intérprete de PHP. La tarea estará terminada cuando una coincidencia fallida ya no deje sin cambios el contenido anterior de $matches del llamador, con cobertura de regresión para ambas funciones.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
php
Área
backend
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.