compact_variation2.phpt 743 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. Test compact() function: ensure compact() doesn't pick up variables declared outside of current scope.
  3. --FILE--
  4. <?php
  5. echo "*** Testing compact() : usage variations - variables outside of current scope ***\n";
  6. $a = 'main.a';
  7. $b = 'main.b';
  8. function f() {
  9. $b = 'f.b';
  10. $c = 'f.c';
  11. var_dump(compact('a','b','c'));
  12. var_dump(compact(array('a','b','c')));
  13. }
  14. f();
  15. ?>
  16. --EXPECTF--
  17. *** Testing compact() : usage variations - variables outside of current scope ***
  18. Warning: compact(): Undefined variable $a in %s on line %d
  19. array(2) {
  20. ["b"]=>
  21. string(3) "f.b"
  22. ["c"]=>
  23. string(3) "f.c"
  24. }
  25. Warning: compact(): Undefined variable $a in %s on line %d
  26. array(2) {
  27. ["b"]=>
  28. string(3) "f.b"
  29. ["c"]=>
  30. string(3) "f.c"
  31. }