1<?php
2/*
3 * This file is part of PHPUnit.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11/**
12 * Error handler that converts PHP errors and warnings to exceptions.
13 */
14class PHPUnit_Util_Regex
15{
16    /**
17     * @param string $pattern
18     * @param string $subject
19     * @param null   $matches
20     * @param int    $flags
21     * @param int    $offset
22     *
23     * @return int
24     */
25    public static function pregMatchSafe($pattern, $subject, $matches = null, $flags = 0, $offset = 0)
26    {
27        $handler_terminator = PHPUnit_Util_ErrorHandler::handleErrorOnce(E_WARNING);
28        $match              = preg_match($pattern, $subject, $matches, $flags, $offset);
29        $handler_terminator(); // cleaning
30
31        return $match;
32    }
33}
34