diff --git a/ext/standard/php_var.h b/ext/standard/php_var.h index 8f1b2d8bc4f33..36c5e156b92b6 100644 --- a/ext/standard/php_var.h +++ b/ext/standard/php_var.h @@ -31,6 +31,7 @@ PHP_FUNCTION(serialize); PHP_FUNCTION(unserialize); PHP_FUNCTION(memory_get_usage); PHP_FUNCTION(memory_get_peak_usage); +PHP_FUNCTION(swap); PHPAPI void php_var_dump(zval *struc, int level); PHPAPI void php_var_export(zval *struc, int level); diff --git a/ext/standard/tests/general_functions/swap_01.phpt b/ext/standard/tests/general_functions/swap_01.phpt new file mode 100644 index 0000000000000..1eeaf8ab18a33 --- /dev/null +++ b/ext/standard/tests/general_functions/swap_01.phpt @@ -0,0 +1,38 @@ +--TEST-- +swap function test +--FILE-- +value); +var_dump($value2->value); + +var_dump(swap()); +var_dump(swap($value1, $value2, $value2)); +?> +--EXPECT-- +bool(true) +string(3) "abc" +int(2) +bool(true) +string(3) "abc" +int(2) +bool(false) +bool(false) \ No newline at end of file diff --git a/ext/standard/var.c b/ext/standard/var.c index 72b2dd5ed5dfd..ad17ec7577e2e 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -1121,6 +1121,27 @@ PHP_FUNCTION(memory_get_peak_usage) { } /* }}} */ +/* {{{ proto bool swipe(mixed var1, mixed var2) + Swaps the value of var1 and var2. */ +PHP_FUNCTION(swap) +{ + zval temp, *val1, *val2; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &val1, &val2) == FAILURE) { + RETURN_FALSE; + } + + ALLOC_INIT_ZVAL(temp); + + ZVAL_COPY_VALUE(temp, val1); + ZVAL_COPY_VALUE(val1, val2); + ZVAL_COPY_VALUE(val2, temp); + + RETURN_TRUE; + +} +/* }}} */ + /* * Local variables: * tab-width: 4