mirror of
https://github.com/php/php-src.git
synced 2024-10-20 16:02:44 +00:00
104 lines
2.6 KiB
Plaintext
104 lines
2.6 KiB
Plaintext
|
--TEST--
|
||
|
filter_data() and FILTER_CALLBACK
|
||
|
--FILE--
|
||
|
<?php
|
||
|
|
||
|
/* Simple callback function */
|
||
|
function test($var) {
|
||
|
return strtoupper($var);
|
||
|
}
|
||
|
|
||
|
var_dump(filter_data("data", FILTER_CALLBACK, "test"));
|
||
|
var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, "test"));
|
||
|
var_dump(filter_data("", FILTER_CALLBACK, "test"));
|
||
|
var_dump(filter_data("qwe", FILTER_CALLBACK, "no such func"));
|
||
|
var_dump(filter_data("qwe", FILTER_CALLBACK, ""));
|
||
|
var_dump(filter_data("qwe", FILTER_CALLBACK));
|
||
|
|
||
|
/* Simple class method callback */
|
||
|
class test_class {
|
||
|
static function test ($var) {
|
||
|
return strtolower($var);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var_dump(filter_data("dAtA", FILTER_CALLBACK, array("test_class", "test")));
|
||
|
var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, array("test_class","test")));
|
||
|
var_dump(filter_data("", FILTER_CALLBACK, array("test_class","test")));
|
||
|
|
||
|
/* empty function without return value */
|
||
|
function test1($var) {
|
||
|
}
|
||
|
|
||
|
var_dump(filter_data("data", FILTER_CALLBACK, "test1"));
|
||
|
var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, "test1"));
|
||
|
var_dump(filter_data("", FILTER_CALLBACK, "test1"));
|
||
|
|
||
|
/* attempting to change data by reference */
|
||
|
function test2(&$var) {
|
||
|
$var = 1;
|
||
|
}
|
||
|
|
||
|
var_dump(filter_data("data", FILTER_CALLBACK, "test2"));
|
||
|
var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, "test2"));
|
||
|
var_dump(filter_data("", FILTER_CALLBACK, "test2"));
|
||
|
|
||
|
/* unsetting data */
|
||
|
function test3(&$var) {
|
||
|
unset($var);
|
||
|
}
|
||
|
|
||
|
var_dump(filter_data("data", FILTER_CALLBACK, "test3"));
|
||
|
var_dump(filter_data("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, "test3"));
|
||
|
var_dump(filter_data("", FILTER_CALLBACK, "test3"));
|
||
|
|
||
|
/* unset data and return value */
|
||
|
function test4(&$var) {
|
||
|
unset($var);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
var_dump(filter_data("data", FILTER_CALLBACK, "test4"));
|
||
|
|
||
|
/* thrown exception in the callback */
|
||
|
function test5(&$var) {
|
||
|
throw new Exception("test");
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
var_dump(filter_data("data", FILTER_CALLBACK, "test5"));
|
||
|
} catch (Exception $e) {
|
||
|
var_dump($e->getMessage());
|
||
|
}
|
||
|
|
||
|
echo "Done\n";
|
||
|
?>
|
||
|
--EXPECTF--
|
||
|
string(4) "DATA"
|
||
|
string(46) "~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?"}{:"
|
||
|
string(0) ""
|
||
|
|
||
|
Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d
|
||
|
NULL
|
||
|
|
||
|
Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d
|
||
|
NULL
|
||
|
|
||
|
Warning: filter_data(): First argument is expected to be a valid callback in %s on line %d
|
||
|
NULL
|
||
|
string(4) "data"
|
||
|
string(46) "~!@#$%^&*()_qwertyuiopasdfghjklzxcvbnm<>>?"}{:"
|
||
|
string(0) ""
|
||
|
NULL
|
||
|
NULL
|
||
|
NULL
|
||
|
NULL
|
||
|
NULL
|
||
|
NULL
|
||
|
NULL
|
||
|
NULL
|
||
|
NULL
|
||
|
int(1)
|
||
|
string(4) "test"
|
||
|
Done
|