Guest User

Conjure Arrays from nothing

a guest
Aug 19th, 2015
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2.  
  3. //$thevar starts undefined
  4.  
  5. $thevar["that"]=5;
  6. var_dump($thevar);
  7.  
  8. // outputs
  9. // array(1) {
  10. //   ["that"]=>
  11. //   int(5)
  12. // }
  13.  
  14. $thevar=null;
  15. var_dump($thevar);
  16. $thevar["that"]=5;
  17. var_dump($thevar);
  18.  
  19. // outputs
  20. // NULL
  21. // array(1) {
  22. //   ["that"]=>
  23. //   int(5)
  24. // }
  25.  
  26. $thevar=false;
  27. var_dump($thevar);
  28. $thevar["that"]=5;
  29. var_dump($thevar);
  30.  
  31. // outputs
  32. // bool(false)
  33. // array(1) {
  34. //   ["that"]=>
  35. //   int(5)
  36. // }
  37.  
  38. // all code above outputs with no warnings
  39.  
  40. $thevar=true;
  41. var_dump($thevar);
  42. $thevar["that"]=5;
  43. var_dump($thevar);
  44.  
  45. // outputs
  46. // bool(true)
  47. // stderr - PHP Warning:  Cannot use a scalar value as an array
  48. // bool(true)
Advertisement
Add Comment
Please, Sign In to add comment