PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/spec/tests/expressions/source_file_inclusion/include.php

http://github.com/facebook/hiphop-php
PHP | 105 lines | 47 code | 36 blank | 22 comment | 8 complexity | e73acac827b94eaa40dd1a81cb96cbb5 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /*
  3. +-------------------------------------------------------------+
  4. | Copyright (c) 2015 Facebook, Inc. (http://www.facebook.com) |
  5. +-------------------------------------------------------------+
  6. */
  7. error_reporting(-1);
  8. echo "Inside file >" . __FILE__ . "< at line >" . __LINE__ .
  9. "< with namespace >" . __NAMESPACE__ . "<\n";
  10. //var_dump(MY_MIN);
  11. //var_dump(MY_MAX);
  12. // Try to include a non-existant file
  13. $fileName = 'unknown.php';
  14. $inc = include $fileName;
  15. echo "include file " . ($inc == 1 ? "does" : "does not") . " exist\n";
  16. // Include an existing file that has its own namespace
  17. $fileName = 'limits' . '.php';
  18. $inc = include $fileName;
  19. var_dump($inc);
  20. echo "Inside file >" . __FILE__ . "< at line >" . __LINE__ .
  21. "< with namespace >" . __NAMESPACE__ . "<\n";
  22. // Include another existing file that has its own namespace
  23. $inc = include('mycolors.php');
  24. var_dump($inc);
  25. echo "Inside file >" . __FILE__ . "< at line >" . __LINE__ .
  26. "< with namespace >" . __NAMESPACE__ . "<\n";
  27. echo "----------------------------------\n";
  28. // Try to access constants defined in an included file
  29. if (defined("MY_MIN"))
  30. echo "MY_MIN is defined with value >" . constant("MY_MIN") . "\n";
  31. else
  32. echo "MY_MIN is not defined\n";
  33. echo "----------------------------------\n";
  34. // Include a file that has no return statement
  35. $inc = include('return_none.php');
  36. var_dump($inc);
  37. // Include a file that has a return statement without a return value
  38. $inc = include('return_without_value.php');
  39. var_dump($inc);
  40. // Include a file that has a return statement with a return value
  41. $inc = include('return_with_value.php');
  42. var_dump($inc);
  43. echo "----------------------------------\n";
  44. // see how low the precedence of include is
  45. //if (include('return_with_value.php') == 987) ;
  46. if ((include('return_with_value.php')) == 987) ;
  47. //if (include('return_with_value.php') | 987) ;
  48. if ((include('return_with_value.php')) | 987) ;
  49. //if (include('return_with_value.php') && 987) ;
  50. if ((include('return_with_value.php')) && 987) ;
  51. //if (include('return_with_value.php') or 987) ;
  52. if ((include('return_with_value.php')) or 987) ;
  53. echo "----------------------------------\n";
  54. // see if included file can access including file's variables, and if including file
  55. // can access the included file's functions and variables
  56. $v1 = 10;
  57. $v2 = "Hello";
  58. echo "Inside file >" . __FILE__ . "< at line >" . __LINE__ . "<\n";
  59. echo "----------------------------------\n";
  60. $inc = include 'test.php';
  61. var_dump($inc);
  62. echo "----------------------------------\n";
  63. echo "Inside file >" . __FILE__ . "< at line >" . __LINE__ . "<\n";
  64. test();
  65. echo "\$local1: $local1\n";
  66. echo "Inside file >" . __FILE__ . "< at line >" . __LINE__ . "<\n";
  67. echo "----------------------------------\n";
  68. // get the set of included files
  69. print_r(get_included_files());