foreachLoop.011.phpt 631 B

12345678910111213141516171819202122232425262728293031323334
  1. --TEST--
  2. Changing from an interable type to a non iterable type during the iteration
  3. --FILE--
  4. <?php
  5. echo "\nChange from array to non iterable:\n";
  6. $a = array(1,2,3);
  7. $b=&$a;
  8. foreach ($a as $v) {
  9. var_dump($v);
  10. $b=1;
  11. }
  12. echo "\nChange from object to non iterable:\n";
  13. $a = new stdClass;
  14. $a->a=1;
  15. $a->b=2;
  16. $b=&$a;
  17. foreach ($a as $v) {
  18. var_dump($v);
  19. $b='x';
  20. }
  21. ?>
  22. --EXPECTF--
  23. Change from array to non iterable:
  24. int(1)
  25. Warning: Invalid argument supplied for foreach() in %s on line 5
  26. Change from object to non iterable:
  27. int(1)
  28. Warning: Invalid argument supplied for foreach() in %s on line 15