Skip to content

Commit 242f8c0

Browse files
authored
Add minimum PHP guard to Phar bootstrap (#1089)
1 parent b258912 commit 242f8c0

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎.github/workflows/testing.yml‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,33 @@ on:
1313
jobs:
1414
test:
1515
uses: wp-cli/.github/.github/workflows/reusable-testing.yml@main
16+
17+
minimum-php-guard:
18+
name: Minimum PHP guard - PHP ${{ matrix.php }}
19+
runs-on: ubuntu-22.04
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
php: ['5.6', '7.1']
24+
steps:
25+
- name: Check out source code
26+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
27+
with:
28+
persist-credentials: false
29+
30+
- name: Set up PHP environment
31+
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
32+
with:
33+
php-version: '${{ matrix.php }}'
34+
coverage: none
35+
36+
- name: Check minimum PHP guard
37+
run: |
38+
if php php/boot-phar.php > stdout.txt 2> stderr.txt; then
39+
echo 'Expected boot-phar.php to reject unsupported PHP version.'
40+
exit 1
41+
fi
42+
43+
test ! -s stdout.txt
44+
printf 'Error: WP-CLI requires PHP 7.2.24 or newer. You are running version %s.\n' "$(php -r 'echo PHP_VERSION;')" > expected.txt
45+
diff -u expected.txt stderr.txt

‎php/boot-phar.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
// This file needs to parse without error in PHP 5.x.
4+
35
if ( 'cli' !== PHP_SAPI ) {
46
echo "WP-CLI only works correctly from the command line, using the 'cli' PHP SAPI.\n",
57
"You're currently executing the WP-CLI binary via the '" . PHP_SAPI . "' PHP SAPI.\n",
@@ -9,6 +11,14 @@
911
die( -1 );
1012
}
1113

14+
if ( version_compare( PHP_VERSION, '7.2.24', '<' ) ) {
15+
fwrite(
16+
STDERR,
17+
sprintf( "Error: WP-CLI requires PHP %s or newer. You are running version %s.\n", '7.2.24', PHP_VERSION )
18+
);
19+
die( -1 );
20+
}
21+
1222
// Store the path to the Phar early on for `Utils\phar-safe-path()` function.
1323
define( 'WP_CLI_PHAR_PATH', Phar::running( true ) );
1424

0 commit comments

Comments
 (0)