PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/runtime/ext/std/ext_std_options.php

https://gitlab.com/Blueprint-Marketing/hhvm
PHP | 451 lines | 186 code | 64 blank | 201 comment | 6 complexity | 1dda480d0f9079f90309a37c5d8272f7 MD5 | raw file
  1. <?hh
  2. /* Set the various assert() control options or just query their current
  3. * settings.
  4. */
  5. <<__Native>>
  6. function assert_options(int $what,
  7. mixed $value = null): mixed;
  8. /* assert() will check the given assertion and take appropriate action if its
  9. * result is FALSE. If the assertion is given as a string it will be
  10. * evaluated as PHP code by assert(). The advantages of a string assertion are
  11. * less overhead when assertion checking is off and messages containing the
  12. * assertion expression when an assertion fails. This means that if you pass a
  13. * boolean condition as assertion this condition will not show up as parameter
  14. * to the assertion function which you may have defined with the
  15. * assert_options() function, the condition is converted to a string before
  16. * calling that handler function, and the boolean FALSE is converted as the
  17. * empty string. Assertions should be used as a debugging feature only. You
  18. * may use them for sanity-checks that test for conditions that should always
  19. * be TRUE and that indicate some programming errors if not or to check for
  20. * the presence of certain features like extension functions or certain system
  21. * limits and features. Assertions should not be used for normal runtime
  22. * operations like input parameter checks. As a rule of thumb your code should
  23. * always be able to work correctly if assertion checking is not activated.
  24. * The behavior of assert() may be configured by assert_options() or by
  25. * .ini-settings described in that functions manual page. The
  26. * assert_options() function and/or ASSERT_CALLBACK configuration directive
  27. * allow a callback function to be set to handle failed assertions. assert()
  28. * callbacks are particularly useful for building automated test suites
  29. * because they allow you to easily capture the code passed to the assertion,
  30. * along with information on where the assertion was made. While this
  31. * information can be captured via other methods, using assertions makes it
  32. * much faster and easier! The callback function should accept three
  33. * arguments. The first argument will contain the file the assertion failed
  34. * in. The second argument will contain the line the assertion failed on and
  35. * the third argument will contain the expression that failed (if any -
  36. * literal values such as 1 or "two" will not be passed via this argument)
  37. */
  38. <<__Native>>
  39. function assert(mixed $assertion, ?string $message = null): mixed;
  40. /* Loads the PHP extension given by the parameter library. Use
  41. * extension_loaded() to test whether a given extension is already available
  42. * or not. This works on both built-in extensions and dynamically loaded ones
  43. * (either through php.ini or dl()). Warning: This function has been removed
  44. * from some SAPI's in PHP 5.3.
  45. */
  46. <<__Native>>
  47. function dl(string $library): int;
  48. /* Finds out whether the extension is loaded.
  49. */
  50. <<__Native>>
  51. function extension_loaded(string $name): bool;
  52. /* This function returns the names of all the modules compiled and loaded in
  53. * the PHP interpreter.
  54. */
  55. <<__Native>>
  56. function get_loaded_extensions(bool $zend_extensions = false): array;
  57. /* This function returns the names of all the functions defined in the module
  58. * indicated by module_name.
  59. */
  60. <<__Native>>
  61. function get_extension_funcs(string $module_name): array;
  62. /* Gets the value of a PHP configuration option. This function will not
  63. * return configuration information set when the PHP was compiled, or read
  64. * from an Apache configuration file. To check whether the system is using a
  65. * configuration file, try retrieving the value of the cfg_file_path
  66. * configuration setting. If this is available, a configuration file is being
  67. * used.
  68. */
  69. <<__Native>>
  70. function get_cfg_var(string $option): mixed;
  71. <<__Native>>
  72. function get_current_user(): string;
  73. /* Returns the names and values of all the constants currently defined. This
  74. * includes those created by extensions as well as those created with the
  75. * define() function.
  76. */
  77. <<__Native>>
  78. function get_defined_constants(bool $categorize = false): array;
  79. <<__Native>>
  80. function get_include_path(): string;
  81. <<__Native>>
  82. function restore_include_path(): void;
  83. /* Sets the include_path configuration option for the duration of the script.
  84. */
  85. <<__Native>>
  86. function set_include_path(mixed $new_include_path): string;
  87. /* Gets the names of all files that have been included using include(),
  88. * include_once(), require() or require_once().
  89. */
  90. <<__Native>>
  91. function get_included_files(): array;
  92. function get_required_files(): array {
  93. return get_included_files();
  94. }
  95. /* Returns the current configuration setting of magic_quotes_gpc Keep in mind
  96. * that attempting to set magic_quotes_gpc at runtime will not work. For more
  97. * information about magic_quotes, see this security section.
  98. */
  99. function get_magic_quotes_gpc(): ?bool {
  100. if (($argc = func_num_args()) != 0) {
  101. trigger_error(__FUNCTION__ . "() expects exactly 0 parameters," .
  102. " $argc given", E_USER_WARNING);
  103. return null;
  104. }
  105. return false;
  106. }
  107. function get_magic_quotes_runtime(): ?bool {
  108. if (($argc = func_num_args()) != 0) {
  109. trigger_error(__FUNCTION__ . "() expects exactly 0 parameters," .
  110. " $argc given", E_USER_WARNING);
  111. return null;
  112. }
  113. return false;
  114. }
  115. <<__Native>>
  116. function getenv(string $varname): mixed;
  117. /* Gets the time of the last modification of the current page. If you're
  118. * interested in getting the last modification time of a different file,
  119. * consider using filemtime().
  120. */
  121. <<__Native>>
  122. function getlastmod(): mixed;
  123. <<__Native>>
  124. function getmygid(): mixed;
  125. /* Gets the inode of the current script.
  126. */
  127. <<__Native>>
  128. function getmyinode(): mixed;
  129. /* Gets the current PHP process ID.
  130. */
  131. <<__Native>>
  132. function getmypid(): mixed;
  133. <<__Native>>
  134. function getmyuid(): mixed;
  135. /* Parses options passed to the script. The options parameter may contain the
  136. * following elements: Individual characters (do not accept values) Characters
  137. * followed by a colon (parameter requires value) Characters followed by two
  138. * colons (optional value) Option values are the first argument after the
  139. * string. It does not matter if a value has leading white space or not.
  140. * Optional values do not accept " " (space) as a separator. The format for
  141. * the options and longopts is almost the same, the only difference is that
  142. * longopts takes an array of options (where each element is the option) where
  143. * as options takes a string (where each character is the option).
  144. */
  145. <<__Native>>
  146. function getopt(string $options,
  147. mixed $longopts = null): array;
  148. /* This is an interface to getrusage(2). It gets data returned from the system
  149. * call.
  150. */
  151. <<__Native>>
  152. function getrusage(int $who = 0): array;
  153. /* Gets resolution of system clock. "man 3 clock_getres" for more details.
  154. */
  155. <<__Native>>
  156. function clock_getres(int $clk_id,
  157. mixed &$sec,
  158. mixed &$nsec): bool;
  159. /* Gets time of a system clock. "man 3 clock_gettime" for more details.
  160. */
  161. <<__Native>>
  162. function clock_gettime(int $clk_id,
  163. mixed &$sec,
  164. mixed &$nsec): bool;
  165. /* Gets number of processors.
  166. */
  167. <<__Native>>
  168. function cpu_get_count(): int;
  169. /* Gets processor model.
  170. */
  171. <<__Native>>
  172. function cpu_get_model(): string;
  173. /* Returns the value of the configuration option on success.
  174. */
  175. <<__Native>>
  176. function ini_get(string $varname): mixed;
  177. /* Gets all configuration options
  178. */
  179. <<__Native>>
  180. function ini_get_all(string $extension = "",
  181. bool $details = true): array;
  182. /* Restores a given configuration option to its original value.
  183. */
  184. <<__Native>>
  185. function ini_restore(string $varname): void;
  186. /* Sets the value of the given configuration option. The configuration option
  187. * will keep this new value during the script's execution, and will be
  188. * restored at the script's ending.
  189. */
  190. <<__Native>>
  191. function ini_set(string $varname,
  192. mixed $newvalue): mixed;
  193. /* Returns the peak of memory, in bytes, that's been allocated to your PHP
  194. * script.
  195. */
  196. <<__Native>>
  197. function memory_get_peak_usage(bool $real_usage = false): int;
  198. /* Returns the amount of memory, in bytes, that's currently being allocated to
  199. * your PHP script.
  200. */
  201. <<__Native>>
  202. function memory_get_usage(bool $real_usage = false): int;
  203. /* Returns the total memory, in bytes, that your PHP script has allocated.
  204. */
  205. <<__Native, __HipHopSpecific>>
  206. function memory_get_allocation(): int;
  207. /* Returns the peak of memory, in bytes, that's been allocated to your PHP
  208. * script since calling memory_start_usage_interval.
  209. */
  210. <<__Native, __HipHopSpecific>>
  211. function hphp_memory_get_interval_peak_usage(bool $real_usage = false): int;
  212. /* Starts per-interval usage tracking to allow peak usage to be tracked
  213. * with more granularity than a per-script basis.
  214. *
  215. * Returns whether the state of interval tracking was changed.
  216. */
  217. <<__Native, __HipHopSpecific>>
  218. function hphp_memory_start_interval(): bool;
  219. /* Stops per-interval usage tracking to allow peak usage to be tracked
  220. * with more granularity than a per-script basis.
  221. *
  222. * Returns whether the state of interval tracking was changed.
  223. */
  224. <<__Native, __HipHopSpecific>>
  225. function hphp_memory_stop_interval(): bool;
  226. /* Retrieve a path to the loaded php.ini file.
  227. */
  228. function php_ini_loaded_file(): mixed {
  229. return false;
  230. }
  231. /* Retrieve a comma-separated list of paths to any additionally loaded ini
  232. * files after php.ini.
  233. */
  234. function php_ini_scanned_files(): mixed {
  235. return false;
  236. }
  237. <<__Native>>
  238. function php_sapi_name(): string;
  239. /* php_uname() returns a description of the operating system PHP is running
  240. * on. This is the same string you see at the very top of the phpinfo()
  241. * output. For the name of just the operating system, consider using the
  242. * PHP_OS constant, but keep in mind this constant will contain the operating
  243. * system PHP was built on. On some older UNIX platforms, it may not be able
  244. * to determine the current OS information in which case it will revert to
  245. * displaying the OS PHP was built on. This will only happen if your uname()
  246. * library call either doesn't exist or doesn't work.
  247. */
  248. <<__Native>>
  249. function php_uname(string $mode = ""): mixed;
  250. /* Outputs a large amount of information about the current state of PHP. This
  251. * includes information about PHP compilation options and extensions, the PHP
  252. * version, server information and environment (if compiled as a module), the
  253. * PHP environment, OS version information, paths, master and local values of
  254. * configuration options, HTTP headers, and the PHP License. Because every
  255. * system is setup differently, phpinfo() is commonly used to check
  256. * configuration settings and for available predefined variables on a given
  257. * system. phpinfo() is also a valuable debugging tool as it contains all
  258. * EGPCS (Environment, GET, POST, Cookie, Server) data.
  259. */
  260. function phpinfo(int $what = 0): bool {
  261. echo '<html>';
  262. echo '<head>';
  263. echo '<title>HHVM phpinfo</title>';
  264. echo '<style type="text/css">';
  265. echo 'body { margin: auto; text-align: center; width: 600px; }';
  266. echo 'hr { margin-top: 30px; }';
  267. echo 'table { border-collapse: collapse; margin: auto; width: 100%; }';
  268. echo 'td { border: 1px solid black; padding: 5px; }';
  269. echo '.l { background-color: #CCF; }';
  270. echo '.r { background-color: #CCC; word-break: break-all; }';
  271. echo '</style>';
  272. echo '</head>';
  273. echo '<body>';
  274. echo '<h1>HHVM Version '.HHVM_VERSION.'</h1>';
  275. echo '<hr>';
  276. echo '<h2>Version</h2>';
  277. echo '<table>';
  278. \__SystemLib\phpinfo_tr('Version', HHVM_VERSION);
  279. \__SystemLib\phpinfo_tr('Version ID', HHVM_VERSION_ID);
  280. \__SystemLib\phpinfo_tr('Debug', HHVM_DEBUG);
  281. \__SystemLib\phpinfo_tr('Compiler ID', HHVM_COMPILER_ID);
  282. \__SystemLib\phpinfo_tr('Repo Schema', HHVM_REPO_SCHEMA);
  283. \__SystemLib\phpinfo_tr('PHP Version', phpversion());
  284. \__SystemLib\phpinfo_tr('Zend Version', zend_version());
  285. \__SystemLib\phpinfo_tr('uname', php_uname());
  286. echo '</table>';
  287. \__SystemLib\phpinfo_table('INI', ini_get_all(null, false));
  288. if (function_exists('getallheaders')) {
  289. \__SystemLib\phpinfo_table('Headers', getallheaders());
  290. }
  291. \__SystemLib\phpinfo_table('$_SERVER', $_SERVER);
  292. \__SystemLib\phpinfo_table('$_ENV', $_ENV);
  293. echo '</body>';
  294. echo '</html>';
  295. return true;
  296. }
  297. /* Returns a string containing the version of the currently running PHP parser
  298. * or extension.
  299. */
  300. <<__Native>>
  301. function phpversion(string $extension = ""): mixed;
  302. /* Adds setting to the server environment. The environment variable will only
  303. * exist for the duration of the current request. At the end of the request
  304. * the environment is restored to its original state. Setting certain
  305. * environment variables may be a potential security breach. The
  306. * safe_mode_allowed_env_vars directive contains a comma-delimited list of
  307. * prefixes. In Safe Mode, the user may only alter environment variables whose
  308. * names begin with the prefixes supplied by this directive. By default, users
  309. * will only be able to set environment variables that begin with PHP_ (e.g.
  310. * PHP_FOO=BAR). Note: if this directive is empty, PHP will let the user
  311. * modify ANY environment variable! The safe_mode_protected_env_vars
  312. * directive contains a comma-delimited list of environment variables, that
  313. * the end user won't be able to change using putenv(). These variables will
  314. * be protected even if safe_mode_allowed_env_vars is set to allow to change
  315. * them.
  316. */
  317. <<__Native>>
  318. function putenv(string $setting): bool;
  319. /* Set the current active configuration setting of magic_quotes_runtime.
  320. * Warning: This function has been DEPRECATED as of PHP 5.3.0. Relying on this
  321. * feature is highly discouraged.
  322. */
  323. function set_magic_quotes_runtime(mixed $new_setting): bool {
  324. trigger_error("Function set_magic_quotes_runtime() is deprecated",
  325. E_USER_DEPRECATED);
  326. if ($new_setting) {
  327. trigger_error(__FUNCTION__ . "() is not supported anymore", E_USER_ERROR);
  328. }
  329. return false;
  330. }
  331. /*
  332. * Alias of set_magic_quotes_runtime()
  333. */
  334. function magic_quotes_runtime(mixed $new_setting): bool {
  335. return set_magic_quotes_runtime($new_setting);
  336. }
  337. /* Set the number of seconds a script is allowed to run. If this is reached,
  338. * the script returns a fatal error. The default limit is 30 seconds or, if it
  339. * exists, the max_execution_time value defined in the php.ini. When called,
  340. * set_time_limit() restarts the timeout counter from zero. In other words, if
  341. * the timeout is the default 30 seconds, and 25 seconds into script execution
  342. * a call such as set_time_limit(20) is made, the script will run for a total
  343. * of 45 seconds before timing out.
  344. */
  345. <<__Native>>
  346. function set_time_limit(int $seconds): void;
  347. /* Returns the path of the directory PHP stores temporary files in by default.
  348. */
  349. <<__Native>>
  350. function sys_get_temp_dir(): string;
  351. /* version_compare() compares two "PHP-standardized" version number strings.
  352. * This is useful if you would like to write programs working only on some
  353. * versions of PHP. The function first replaces _, - and + with a dot . in
  354. * the version strings and also inserts dots . before and after any non number
  355. * so that for example '4.3.2RC1' becomes '4.3.2.RC.1'. Then it splits the
  356. * results like if you were using explode('.', $ver). Then it compares the
  357. * parts starting from left to right. If a part contains special version
  358. * strings these are handled in the following order: any string not found in
  359. * this list < dev < alpha = a < beta = b < RC = rc < # < pl = p. This way not
  360. * only versions with different levels like '4.1' and '4.1.2' can be compared
  361. * but also any PHP specific version containing development state.
  362. */
  363. <<__Native>>
  364. function version_compare(string $version1,
  365. string $version2,
  366. string $sop = ""): mixed;
  367. /* Returns a string containing the version of the currently running Zend
  368. * Engine.
  369. */
  370. <<__Native>>
  371. function zend_version(): string;
  372. namespace __SystemLib {
  373. <<__Native>>
  374. function assert(mixed $assertion, ?string $message = null): ?bool;
  375. function phpinfo_tr($l, $d) {
  376. echo "<tr><td class=\"l\">$l</td><td class=\"r\">$d</td></tr>";
  377. }
  378. function phpinfo_table($l, $a) {
  379. echo '<hr>';
  380. echo "<h2>$l</h2>";
  381. echo '<table>';
  382. foreach ($a as $k => $v) {
  383. phpinfo_tr($k, print_r($v, true));
  384. }
  385. echo '</table>';
  386. }
  387. }