3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test_position($input) { $_POST['position'] = $input; // Original code $original = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; // Alternative 1: !empty() $empty_check = ! empty( $_POST['position'] ) ? (int) $_POST['position'] : -1; // Alternative 3: null coalescing operator $null_coalesce = (int) ($_POST['position'] ?? '-1'); echo "Input: $input\n"; echo "Original: $original\n"; echo "!empty() check: $empty_check\n"; echo "Null coalescing: $null_coalesce\n"; echo "-------------------------\n"; } // Test cases $test_inputs = ['5', '0', 'xyz', '', null]; foreach ($test_inputs as $input) { test_position($input); } ?>
Output for git.master_jit, git.master
Input: 5 Original: 5 !empty() check: 5 Null coalescing: 5 ------------------------- Input: 0 Original: -1 !empty() check: -1 Null coalescing: 0 ------------------------- Input: xyz Original: -1 !empty() check: 0 Null coalescing: 0 ------------------------- Input: Original: -1 !empty() check: -1 Null coalescing: 0 ------------------------- Input: Original: -1 !empty() check: -1 Null coalescing: -1 -------------------------

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:
40.28 ms | 410 KiB | 6 Q