Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Constants</title>
  4. </head>
  5. <body>
  6. <?php
  7. /* Constants can't change their values after being defined
  8. Constant names use all capital letters and no dollar sign
  9. */
  10.  
  11. // Assignment to a variable
  12. $max_width = 980;
  13. // Assignment to a constant
  14. define("MAX_WIDTH", 980);
  15.  
  16. // Referencing the value of a constant
  17. echo MAX_WIDTH; echo "<br />";
  18.  
  19. // Trying to change a constant will give an error:
  20. // MAX_WIDTH += 1;
  21.  
  22. // But changing a variable will not.
  23. $max_width += 1;
  24. echo $max_width;
  25.  
  26. /*
  27. Note that once a page is returned, a constant CAN be redefined by another PHP page.
  28. For example:
  29. Browser Request 1 -> page1.php -> SIZE defined as 10 -> PHP page finishes -> Page 1 Returned
  30. Browser Request 2 -> page2.php -> SIZE defined as 20 -> PHP page finishes -> Page 2 Returned
  31.  
  32. SIZE must remain 10 throughout page1.php,
  33. but when the 2nd request comes in SIZE is not defined
  34. */
  35. ?>
  36. </body>
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement