3v4l.org

run code in 300+ PHP versions simultaneously
<?php ob_start(); echo '#+++++++++++++++++++++++++++++++++++#' . PHP_EOL; echo '# Checking if a constant is defined #' . PHP_EOL; echo '# always retuns (bool)false in PHP. #' . PHP_EOL; echo '# Even if it has been defined! #' . PHP_EOL; echo '#+++++++++++++++++++++++++++++++++++#' . PHP_EOL; error_reporting(E_ALL); echo 'Testing on PHP version ' . PHP_VERSION . PHP_EOL . PHP_EOL; ob_flush(); flush(); sleep(1); echo 'Checking if `__DIR__` is defined...' . PHP_EOL; if (!defined('__DIR__')) { ob_flush(); flush(); sleep(2); echo 'Nope, `defined()` returned `(bool)false`.' . PHP_EOL; echo 'So, seems like the magic constant `__DIR__` is not defined.' . PHP_EOL . PHP_EOL; ob_flush(); flush(); sleep(2); echo 'No prob. Executing `define(\'__DIR__\', \'/foo/bar\')`...' . PHP_EOL; define('__DIR__', '/foo/bar'); ob_flush(); flush(); sleep(1); echo 'Done, defined `__DIR__` as "/foo/bar".' . PHP_EOL . PHP_EOL; ob_flush(); flush(); sleep(1); echo 'Double-checking `__DIR__` is defined now...' . PHP_EOL; ob_flush(); flush(); sleep(2); if (!defined('__DIR__')) { echo 'WTF, `defined(\'__DIR__\')` again returned `(bool)false`?!' . PHP_EOL; } else{ echo 'Strike, this time `defined(\'__DIR__\')` returned `(bool)true`.' . PHP_EOL; echo 'So, seems like `__DIR__` was successfully defined. :)' . PHP_EOL . PHP_EOL; } } else{ echo 'Yep, `defined(\'__DIR__\')` returned `(bool)true`.' . PHP_EOL; echo 'The magic constant `__DIR__` seems to be defined.' . PHP_EOL . PHP_EOL; } ob_flush(); flush(); sleep(2); echo 'Finally, here is the result of `var_dump(__DIR__)`:' . PHP_EOL; var_dump(__DIR__); ob_flush(); flush(); sleep(1); if ("/foo/bar" != __DIR__) { echo 'But, wait..' . PHP_EOL; echo 'I defined `__DIR__` as "/foo/bar" - not as "' . __DIR__ .'"?! What happend?' . PHP_EOL . PHP_EOL; ob_flush(); flush(); sleep(1); echo 'In fact, `__DIR__` was already defined when first checked.' . PHP_EOL; echo 'But 1) `defined(\'__MAGIC_CONSTANT__\')` ALWAYS returns `(bool)false`' . PHP_EOL; echo 'and 2) defined constants can not be overwritten.' . PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
#+++++++++++++++++++++++++++++++++++# # Checking if a constant is defined # # always retuns (bool)false in PHP. # # Even if it has been defined! # #+++++++++++++++++++++++++++++++++++# Testing on PHP version 8.3.0-dev Checking if `__DIR__` is defined...
Process exited with code 137.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.84 ms | 401 KiB | 8 Q