compact_variation2.phpt 824 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. Test compact() function: ensure compact() doesn't pick up variables declared outside of current scope.
  3. --FILE--
  4. <?php
  5. /* Prototype : proto array compact(mixed var_names [, mixed ...])
  6. * Description: Creates a hash containing variables and their values
  7. * Source code: ext/standard/array.c
  8. * Alias to functions:
  9. */
  10. echo "*** Testing compact() : usage variations - variables outside of current scope ***\n";
  11. $a = 'main.a';
  12. $b = 'main.b';
  13. function f() {
  14. $b = 'f.b';
  15. $c = 'f.c';
  16. var_dump(compact('a','b','c'));
  17. var_dump(compact(array('a','b','c')));
  18. }
  19. f();
  20. ?>
  21. ==Done==
  22. --EXPECTF--
  23. *** Testing compact() : usage variations - variables outside of current scope ***
  24. array(2) {
  25. ["b"]=>
  26. string(3) "f.b"
  27. ["c"]=>
  28. string(3) "f.c"
  29. }
  30. array(2) {
  31. ["b"]=>
  32. string(3) "f.b"
  33. ["c"]=>
  34. string(3) "f.c"
  35. }
  36. ==Done==