mirror of
https://github.com/php/php-src.git
synced 2025-08-17 14:38:49 +02:00
More error conditions
This commit is contained in:
parent
cda8e60638
commit
4180226117
3 changed files with 34 additions and 6 deletions
|
@ -1275,8 +1275,8 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub
|
||||||
*replace_value,
|
*replace_value,
|
||||||
empty_replace;
|
empty_replace;
|
||||||
zend_string *result;
|
zend_string *result;
|
||||||
zend_string *subject_str = zval_get_string(subject);
|
|
||||||
uint32_t replace_idx;
|
uint32_t replace_idx;
|
||||||
|
zend_string *subject_str = zval_get_string(subject);
|
||||||
|
|
||||||
/* FIXME: This might need to be changed to STR_EMPTY_ALLOC(). Check if this zval could be dtor()'ed somehow */
|
/* FIXME: This might need to be changed to STR_EMPTY_ALLOC(). Check if this zval could be dtor()'ed somehow */
|
||||||
ZVAL_EMPTY_STRING(&empty_replace);
|
ZVAL_EMPTY_STRING(&empty_replace);
|
||||||
|
@ -1512,6 +1512,7 @@ static PHP_FUNCTION(preg_replace_callback_array)
|
||||||
ZEND_PARSE_PARAMETERS_END();
|
ZEND_PARSE_PARAMETERS_END();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ZVAL_UNDEF(&zv);
|
||||||
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(pattern), num_idx, str_idx, replace) {
|
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(pattern), num_idx, str_idx, replace) {
|
||||||
if (str_idx) {
|
if (str_idx) {
|
||||||
ZVAL_STR_COPY(®ex, str_idx);
|
ZVAL_STR_COPY(®ex, str_idx);
|
||||||
|
@ -1537,8 +1538,18 @@ static PHP_FUNCTION(preg_replace_callback_array)
|
||||||
zval_ptr_dtor(return_value);
|
zval_ptr_dtor(return_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZVAL_COPY_VALUE(return_value, &zv);
|
|
||||||
zval_ptr_dtor(®ex);
|
zval_ptr_dtor(®ex);
|
||||||
|
|
||||||
|
if (Z_ISUNDEF(zv)) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
|
ZVAL_COPY_VALUE(return_value, &zv);
|
||||||
|
|
||||||
|
if (UNEXPECTED(EG(exception))) {
|
||||||
|
zval_dtor(return_value);
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
} ZEND_HASH_FOREACH_END();
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
if (zcount) {
|
if (zcount) {
|
||||||
|
|
|
@ -4,12 +4,19 @@ preg_replace_callback_array() basic functions
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
throw new Exception();
|
throw new Exception('f');
|
||||||
|
}
|
||||||
|
|
||||||
|
function a() {
|
||||||
|
return __FUNCTION__;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var_dump(preg_replace_callback_array(array('/\w/' => 'f'), 'z'));
|
var_dump($c = preg_replace_callback_array(array('/\w*/' => 'f', '/\w/' => 'a'), 'z'));
|
||||||
} catch(Exception $e) {}
|
} catch(Exception $e) {
|
||||||
|
var_dump($e->getMessage());
|
||||||
|
}
|
||||||
|
var_dump($c);
|
||||||
|
|
||||||
function g($x) {
|
function g($x) {
|
||||||
return "'$x[0]'";
|
return "'$x[0]'";
|
||||||
|
@ -22,6 +29,10 @@ var_dump(preg_replace_callback_array(array('~\A.~' => 'g'), array(array('xyz')))
|
||||||
var_dump(preg_replace_callback_array(array('~\A.~' => create_function('$m', 'return strtolower($m[0]);')), 'ABC'));
|
var_dump(preg_replace_callback_array(array('~\A.~' => create_function('$m', 'return strtolower($m[0]);')), 'ABC'));
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
|
string(1) "f"
|
||||||
|
|
||||||
|
Notice: Undefined variable: c in %spreg_replace_callback_array.php on line %d
|
||||||
|
NULL
|
||||||
array(3) {
|
array(3) {
|
||||||
[0]=>
|
[0]=>
|
||||||
string(12) "'a' 'b3' bcd"
|
string(12) "'a' 'b3' bcd"
|
||||||
|
|
|
@ -18,7 +18,10 @@ var_dump($b);
|
||||||
$b = "";
|
$b = "";
|
||||||
var_dump(preg_replace_callback_array(array("xx" => "s"), $a, -1, $b));
|
var_dump(preg_replace_callback_array(array("xx" => "s"), $a, -1, $b));
|
||||||
var_dump($b);
|
var_dump($b);
|
||||||
|
function f() {
|
||||||
|
}
|
||||||
|
|
||||||
|
var_dump(preg_replace_callback_array(array('/\w' => 'f'), 'z'));
|
||||||
echo "Done\n";
|
echo "Done\n";
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
|
@ -44,8 +47,11 @@ Warning: preg_replace_callback() expects parameter 4 to be integer, array given
|
||||||
NULL
|
NULL
|
||||||
string(0) ""
|
string(0) ""
|
||||||
|
|
||||||
Warning: preg_replace_callback_array(): 's' is not a valid callback in %s on line %d
|
Warning: preg_replace_callback_array(): 's' is not a valid callback in %spreg_replace_callback_array2.php on line %d
|
||||||
array(0) {
|
array(0) {
|
||||||
}
|
}
|
||||||
string(0) ""
|
string(0) ""
|
||||||
|
|
||||||
|
Warning: preg_replace_callback_array(): No ending delimiter '/' found in %spreg_replace_callback_array2.php on line %d
|
||||||
|
NULL
|
||||||
Done
|
Done
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue