print_basic.phpt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. --TEST--
  2. Test print() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : int print ( string $arg )
  6. * Description: Output a string
  7. * Source code: n/a, print is a language construct not an extension function
  8. * Test based on php.net manual example.
  9. */
  10. echo "*** Testing print() : basic functionality ***\n";
  11. echo "\n-- Iteration 1 --\n";
  12. print("Hello World");
  13. echo "\n-- Iteration 2 --\n";
  14. print "print() also works without parentheses.";
  15. echo "\n-- Iteration 3 --\n";
  16. print "This spans
  17. multiple lines. The newlines will be
  18. output as well";
  19. echo "\n-- Iteration 4 --\n";
  20. print "This also spans\nmultiple lines. The newlines will be\noutput as well.";
  21. echo "\n-- Iteration 5 --\n";
  22. print "escaping characters is done \"Like this\".";
  23. // You can use variables inside of a print statement
  24. $foo = "foobar";
  25. $bar = "barbaz";
  26. echo "\n-- Iteration 6 --\n";
  27. print "foo is $foo"; // foo is foobar
  28. // You can also use arrays
  29. $bar = array("value" => "foo");
  30. echo "\n-- Iteration 7 --\n";
  31. print "this is {$bar['value']} !"; // this is foo !
  32. // Using single quotes will print the variable name, not the value
  33. echo "\n-- Iteration 8 --\n";
  34. print 'foo is $foo'; // foo is $foo
  35. // If you are not using any other characters, you can just print variables
  36. echo "\n-- Iteration 9 --\n";
  37. print $foo; // foobar
  38. echo "\n-- Iteration 10 --\n";
  39. $variable = "VARIABLE";
  40. print <<<END
  41. This uses the "here document" syntax to output
  42. multiple lines with $variable interpolation. Note
  43. that the here document terminator must appear on a
  44. line with just a semicolon no extra whitespace!\n
  45. END;
  46. ?>
  47. ===DONE===
  48. --EXPECT--
  49. *** Testing print() : basic functionality ***
  50. -- Iteration 1 --
  51. Hello World
  52. -- Iteration 2 --
  53. print() also works without parentheses.
  54. -- Iteration 3 --
  55. This spans
  56. multiple lines. The newlines will be
  57. output as well
  58. -- Iteration 4 --
  59. This also spans
  60. multiple lines. The newlines will be
  61. output as well.
  62. -- Iteration 5 --
  63. escaping characters is done "Like this".
  64. -- Iteration 6 --
  65. foo is foobar
  66. -- Iteration 7 --
  67. this is foo !
  68. -- Iteration 8 --
  69. foo is $foo
  70. -- Iteration 9 --
  71. foobar
  72. -- Iteration 10 --
  73. This uses the "here document" syntax to output
  74. multiple lines with VARIABLE interpolation. Note
  75. that the here document terminator must appear on a
  76. line with just a semicolon no extra whitespace!
  77. ===DONE===