3v4l.org

run code in 300+ PHP versions simultaneously
<?php define( 'TESTDOX', true ); function wp_is_development_mode( $mode = null ) { $current_mode = wp_get_development_mode(); if ( empty( $current_mode ) ) { return '' === $mode; } // Return true if the current mode encompasses all modes. if ( 'all' === $current_mode ) { return true; } // Return true if the current mode is the given mode. return $mode === $current_mode; } // Polyfill. global $test_development_mode; function wp_get_development_mode() { global $test_development_mode; return $test_development_mode; } // Test cases. $dataset = array( 'both are empty strings' => array( 'mode' => '', 'dev' => '', 'expected' => true, ), 'both are non-empty, matching strings' => array( 'mode' => 'plugin', 'dev' => 'plugin', 'expected' => true, ), 'both are non-empty, unmatching strings' => array( 'mode' => 'core', 'dev' => 'theme', 'expected' => false, ), '$mode is null and development mode is an empty string' => array( 'mode' => null, 'dev' => '', 'expected' => false, ), '$mode is an empty string, development mode is a non-empty string' => array( 'mode' => '', 'dev' => 'core', 'expected' => false, ), '$mode is a non-empty string, development mode is an empty string' => array( 'mode' => 'core', 'dev' => '', 'expected' => false, ), ); foreach ( $dataset as $name => $data ) { $test_development_mode = $data['dev']; $actual = null === $data['mode'] ? wp_is_development_mode() : wp_is_development_mode( $data['mode'] ); $result = $actual === $data['expected'] ? '.' : 'F'; if ( defined( 'TESTDOX' ) && TESTDOX ) { echo '.' === $result ? 'PASS' : 'FAIL', ': ', $name, ' (', var_export( $data['expected'], true ), ')', PHP_EOL; } else { echo $result; } }
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
PASS: both are empty strings (true) PASS: both are non-empty, matching strings (true) PASS: both are non-empty, unmatching strings (false) PASS: $mode is null and development mode is an empty string (false) PASS: $mode is an empty string, development mode is a non-empty string (false) PASS: $mode is a non-empty string, development mode is an empty string (false)

preferences:
57.32 ms | 407 KiB | 5 Q