PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/filter/tests/029.php

http://github.com/facebook/hiphop-php
PHP | 72 lines | 50 code | 15 blank | 7 comment | 0 complexity | 54ecaa523a3152ab831f323bdc86504f MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Simple callback function */
  3. function test($var) {
  4. return strtoupper($var);
  5. }
  6. var_dump(filter_var("data", FILTER_CALLBACK, array("options"=>"test")));
  7. var_dump(filter_var("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, array("options"=>"test")));
  8. var_dump(filter_var("", FILTER_CALLBACK, array("options"=>"test")));
  9. var_dump(filter_var("qwe", FILTER_CALLBACK, array("options"=>"no such func")));
  10. var_dump(filter_var("qwe", FILTER_CALLBACK, array("options"=>"")));
  11. var_dump(filter_var("qwe", FILTER_CALLBACK));
  12. /* Simple class method callback */
  13. class test_class {
  14. static function test ($var) {
  15. return strtolower($var);
  16. }
  17. }
  18. var_dump(filter_var("dAtA", FILTER_CALLBACK, array("options"=>array("test_class", "test"))));
  19. var_dump(filter_var("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, array("options"=>array("test_class","test"))));
  20. var_dump(filter_var("", FILTER_CALLBACK, array("options"=>array("test_class","test"))));
  21. /* empty function without return value */
  22. function test1($var) {
  23. }
  24. var_dump(filter_var("data", FILTER_CALLBACK, array("options"=>"test1")));
  25. var_dump(filter_var("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, array("options"=>"test1")));
  26. var_dump(filter_var("", FILTER_CALLBACK, array("options"=>"test1")));
  27. /* attempting to change data by reference */
  28. function test2(&$var) {
  29. $var = 1;
  30. }
  31. var_dump(filter_var("data", FILTER_CALLBACK, array("options"=>"test2")));
  32. var_dump(filter_var("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, array("options"=>"test2")));
  33. var_dump(filter_var("", FILTER_CALLBACK, array("options"=>"test2")));
  34. /* unsetting data */
  35. function test3(&$var) {
  36. unset($var);
  37. }
  38. var_dump(filter_var("data", FILTER_CALLBACK, array("options"=>"test3")));
  39. var_dump(filter_var("~!@#$%^&*()_QWERTYUIOPASDFGHJKLZXCVBNM<>>?\"}{:", FILTER_CALLBACK, array("options"=>"test3")));
  40. var_dump(filter_var("", FILTER_CALLBACK, array("options"=>"test3")));
  41. /* unset data and return value */
  42. function test4(&$var) {
  43. unset($var);
  44. return 1;
  45. }
  46. var_dump(filter_var("data", FILTER_CALLBACK, array("options"=>"test4")));
  47. /* thrown exception in the callback */
  48. function test5(&$var) {
  49. throw new Exception("test");
  50. }
  51. try {
  52. var_dump(filter_var("data", FILTER_CALLBACK, array("options"=>"test5")));
  53. } catch (Exception $e) {
  54. var_dump($e->getMessage());
  55. }
  56. echo "Done\n";
  57. ?>