From 1122cb44575c559fdedb3687e08c3286bf37a430 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 27 Feb 2022 12:34:36 +0100 Subject: [PATCH 01/11] PHP 8.1 is supported --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b3929dd..2a5dcdb 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ load these APIs just include the `handlers/bootstrap.php` file. Installation ------------ -The master branch supports PHP version 7.0 to 8.0. Use the [version 0.2][version_0_2] -branch for PHP 5 support. +The master branch supports PHP version 7.0 to 8.1. The extension is incompatible +with the JIT compiler. ### Unix From 881e3e7d429994e9828825f05d9fb11945a2fbd9 Mon Sep 17 00:00:00 2001 From: "anton.solovev" Date: Mon, 15 Aug 2022 16:43:51 +0300 Subject: [PATCH 02/11] Add github actions workflow --- .github/workflows/common.yml | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/common.yml diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml new file mode 100644 index 0000000..e854a8a --- /dev/null +++ b/.github/workflows/common.yml @@ -0,0 +1,56 @@ +name: Run tests + +on: + push: + branches: [master] + pull_request: + branches: [master] + +permissions: + contents: read + +jobs: + tests: + name: Execute tests on ${{ matrix.operating-system }} with PHP ${{ matrix.php-versions }} + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: + - "ubuntu-latest" + - "macos-latest" + php-versions: + - "7.0" + - "7.1" + - "7.2" + - "7.3" + - "7.4" + - "8.0" + - "8.1" + - "nightly" + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: none + tools: phpize + env: + update: true + + - uses: actions/checkout@v3 + + - name: Setup extension + run: | + phpize + ./configure --enable-scalar-objects + make + sudo make install + + - name: Make test + run: make test + + - name: Run tests + env: + REPORT_EXIT_STATUS: 1 + run: php run-tests.php -p `which php` --show-diff -d extension=`pwd`/modules/scalar_objects.so -q From ee9c514a8028efffacae4aab5157cd8b7b06125d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 28 Aug 2022 11:55:29 +0200 Subject: [PATCH 03/11] Initialize T for indirection function T is now used for internal functions as well. --- scalar_objects.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scalar_objects.c b/scalar_objects.c index 84cf290..a41c0bd 100644 --- a/scalar_objects.c +++ b/scalar_objects.c @@ -161,6 +161,9 @@ static zend_function *scalar_objects_get_indirection_func( ind->fn.fn_flags = ZEND_ACC_CALL_VIA_HANDLER | (fbc->common.fn_flags & keep_flags); ind->fn.num_args = fbc->common.num_args - 1; ind->fn.required_num_args = fbc->common.required_num_args - 1; +#if PHP_VERSION_ID >= 80200 + ind->fn.T = 0; +#endif ind->fbc = fbc; if (fbc->common.arg_info) { From 12cf23c25c46d58886a8365bc056d54d5b9dcb19 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 28 Aug 2022 12:01:52 +0200 Subject: [PATCH 04/11] Initialize attributes for indirection function This become problematic in PHP 8.2, because attributes are checked during backtrace generation. --- scalar_objects.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scalar_objects.c b/scalar_objects.c index a41c0bd..7c25600 100644 --- a/scalar_objects.c +++ b/scalar_objects.c @@ -161,6 +161,9 @@ static zend_function *scalar_objects_get_indirection_func( ind->fn.fn_flags = ZEND_ACC_CALL_VIA_HANDLER | (fbc->common.fn_flags & keep_flags); ind->fn.num_args = fbc->common.num_args - 1; ind->fn.required_num_args = fbc->common.required_num_args - 1; +#if PHP_VERSION_ID >= 80000 + ind->fn.attributes = NULL; +#endif #if PHP_VERSION_ID >= 80200 ind->fn.T = 0; #endif From 14cef3d73a92d595c5b257955e61ea92194fdf49 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 28 Aug 2022 12:05:25 +0200 Subject: [PATCH 05/11] Fix behavior of string->chunk() for empty string This matches the PHP 8.2 str_split() behavior. --- doc/string_api.md | 1 + handlers/string.php | 4 ++++ tests/string.phpt | 4 +--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/string_api.md b/doc/string_api.md index 6c4e87e..e597934 100644 --- a/doc/string_api.md +++ b/doc/string_api.md @@ -325,6 +325,7 @@ length of the main string is not divisible by the chunk length, then the last ch > * This function corresponds to `str_split`. * It is perfectly valid to have a chunk length that is longer than the main string. + * Chunking an empty string results in an empty array. * The name `chunk()` was chosen, because `split()` seems more appropriate for the `explode` equivalent. Furthermore the corresponding array functionality is also named `chunk()`. diff --git a/handlers/string.php b/handlers/string.php index 7090dcd..3e49d07 100644 --- a/handlers/string.php +++ b/handlers/string.php @@ -125,6 +125,10 @@ public static function split($self, $separator, $limit = PHP_INT_MAX) { public static function chunk($self, $chunkLength = 1) { $self->verifyPositive($chunkLength, 'Chunk length'); + if ($self === '') { + // str_split() prior to PHP 8.2 is buggy and returns [''] instead. + return []; + } return str_split($self, $chunkLength); } diff --git a/tests/string.phpt b/tests/string.phpt index 2cfa1ec..ec61687 100644 --- a/tests/string.phpt +++ b/tests/string.phpt @@ -499,9 +499,7 @@ count(""): int(1) count("", 0): int(1) count("", 0, 0): int(1) repeat(3): string(0) "" -chunk(3): array(1) { - [0]=> - string(0) "" +chunk(3): array(0) { } replace("foo", "bar"): string(0) "" replace("foo", "bar", 1): string(0) "" From e0f8669597d7f323dd61052cd92f0b00a54979fe Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 28 Aug 2022 12:14:36 +0200 Subject: [PATCH 06/11] Add support for named parameters --- scalar_objects.c | 1 + tests/named_params.phpt | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/named_params.phpt diff --git a/scalar_objects.c b/scalar_objects.c index 7c25600..0fc66fd 100644 --- a/scalar_objects.c +++ b/scalar_objects.c @@ -159,6 +159,7 @@ static zend_function *scalar_objects_get_indirection_func( ind->fn.handler = scalar_objects_indirection_func; ind->fn.scope = ce; ind->fn.fn_flags = ZEND_ACC_CALL_VIA_HANDLER | (fbc->common.fn_flags & keep_flags); + ind->fn.fn_flags |= ZEND_ACC_USER_ARG_INFO; ind->fn.num_args = fbc->common.num_args - 1; ind->fn.required_num_args = fbc->common.required_num_args - 1; #if PHP_VERSION_ID >= 80000 diff --git a/tests/named_params.phpt b/tests/named_params.phpt new file mode 100644 index 0000000..9934392 --- /dev/null +++ b/tests/named_params.phpt @@ -0,0 +1,29 @@ +--TEST-- +Named parameters +--SKIPIF-- += 8.0 only'); +?> +--FILE-- +test(prefix: "P")); +var_dump($string->test(suffix: "S")); +var_dump($string->test(prefix: "P", suffix: "S")); +var_dump($string->test(suffix: "S", prefix: "P")); + +?> +--EXPECT-- +string(5) "PTest" +string(5) "TestS" +string(6) "PTestS" +string(6) "PTestS" From ad1d050b3987a76a62e524a412c6608c8fe4f6ad Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 28 Aug 2022 12:16:58 +0200 Subject: [PATCH 07/11] Try to fix appveyor build This just copies the install.ps1 from apcu --- .appveyor/install.ps1 | 65 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/.appveyor/install.ps1 b/.appveyor/install.ps1 index fbcd032..6ee46d7 100644 --- a/.appveyor/install.ps1 +++ b/.appveyor/install.ps1 @@ -1,64 +1,61 @@ $ErrorActionPreference = "Stop" -if (-not (Test-Path 'C:\build-cache')) { - [void](New-Item 'C:\build-cache' -ItemType 'directory') +if (-not (Test-Path 'c:\build-cache')) { + [void](New-Item 'c:\build-cache' -ItemType 'directory') } $bname = "php-sdk-$env:BIN_SDK_VER.zip" -if (-not (Test-Path "C:\build-cache\$bname")) { - Invoke-WebRequest "https://github.com/Microsoft/php-sdk-binary-tools/archive/$bname" -OutFile "C:\build-cache\$bname" +Write-Host $bname +if (-not (Test-Path c:\build-cache\$bname)) { + Invoke-WebRequest "https://github.com/microsoft/php-sdk-binary-tools/archive/$bname" -OutFile "c:\build-cache\$bname" } $dname0 = "php-sdk-binary-tools-php-sdk-$env:BIN_SDK_VER" $dname1 = "php-sdk-$env:BIN_SDK_VER" -if (-not (Test-Path "C:\build-cache\$dname1")) { - Expand-Archive "C:\build-cache\$bname" 'C:\build-cache' - Move-Item "C:\build-cache\$dname0" "C:\build-cache\$dname1" +if (-not (Test-Path 'c:\build-cache\$dname1')) { + Expand-Archive "c:\build-cache\$bname" "c:\build-cache" + Move-Item "c:\build-cache\$dname0" "c:\build-cache\$dname1" } -$gareleases = Invoke-WebRequest "https://windows.php.net/downloads/releases/releases.json" | ConvertFrom-Json -$qareleases = Invoke-WebRequest "https://windows.php.net/downloads/qa/releases.json" | ConvertFrom-Json -$garev = [regex]::split($gareleases.$env:PHP_VER.version, '[^\d]')[2] -$qarev = [regex]::split($qareleases.$env:PHP_VER.version, '[^\d]')[2] -if ($qarev -gt $garev) { - $phpversion = $qareleases.$env:PHP_VER.version - $phprelease = 'QA' +$releases = @{ + '7.0' = '7.0.33'; + '7.1' = '7.1.33'; + '7.2' = '7.2.34'; + '7.3' = '7.3.33'; +} +if ($releases.ContainsKey($env:PHP_VER)) { + $phpversion = $releases.$env:PHP_VER; + $base_url = 'http://windows.php.net/downloads/releases/archives'; } else { - $phpversion = $gareleases.$env:PHP_VER.version - $phprelease = 'GA' + $releases = Invoke-WebRequest https://windows.php.net/downloads/releases/releases.json | ConvertFrom-Json + $phpversion = $releases.$env:PHP_VER.version + $base_url = 'http://windows.php.net/downloads/releases'; } $ts_part = '' if ($env:TS -eq '0') { $ts_part += '-nts' } + $bname = "php-devel-pack-$phpversion$ts_part-Win32-$env:VC-$env:ARCH.zip" -if (-not (Test-Path "C:\build-cache\$bname")) { - if ($phprelease -eq "GA") { - Invoke-WebRequest "https://windows.php.net/downloads/releases/$bname" -OutFile "C:\build-cache\$bname" - } else { - Invoke-WebRequest "https://windows.php.net/downloads/qa/$bname" -OutFile "C:\build-cache\$bname" - } +if (-not (Test-Path "c:\build-cache\$bname")) { + Invoke-WebRequest "$base_url/$bname" -OutFile "c:\build-cache\$bname" } $dname0 = "php-$phpversion-devel-$env:VC-$env:ARCH" $dname1 = "php-$phpversion$ts_part-devel-$env:VC-$env:ARCH" -if (-not (Test-Path "C:\build-cache\$dname1")) { - Expand-Archive "C:\build-cache\$bname" 'C:\build-cache' +if (-not (Test-Path "c:\build-cache\$dname1")) { + Expand-Archive "c:\build-cache\$bname" "c:\build-cache" if ($dname0 -ne $dname1) { - Move-Item "C:\build-cache\$dname0" "C:\build-cache\$dname1" + Move-Item "c:\build-cache\$dname0" "c:\build-cache\$dname1" } } -$env:PATH = "C:\build-cache\$dname1;$env:PATH" +$env:PATH = "c:\build-cache\$dname1;$env:PATH" $bname = "php-$phpversion$ts_part-Win32-$env:VC-$env:ARCH.zip" -if (-not (Test-Path "C:\build-cache\$bname")) { - if ($phprelease -eq "GA") { - Invoke-WebRequest "https://windows.php.net/downloads/releases/$bname" -OutFile "C:\build-cache\$bname" - } else { - Invoke-WebRequest "https://windows.php.net/downloads/qa/$bname" -OutFile "C:\build-cache\$bname" - } +if (-not (Test-Path "c:\build-cache\$bname")) { + Invoke-WebRequest "$base_url/$bname" -OutFile "c:\build-cache\$bname" } $dname = "php-$phpversion$ts_part-$env:VC-$env:ARCH" -if (-not (Test-Path "C:\build-cache\$dname")) { - Expand-Archive "C:\build-cache\$bname" "C:\build-cache\$dname" +if (-not (Test-Path "c:\build-cache\$dname")) { + Expand-Archive "c:\build-cache\$bname" "c:\build-cache\$dname" } $env:PATH = "c:\build-cache\$dname;$env:PATH" From 2215966ee0bf550f58c16091724d5e7a03df7d2a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 10 Sep 2022 17:49:28 +0200 Subject: [PATCH 08/11] Fix GCC 12 warning --- scalar_objects.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scalar_objects.c b/scalar_objects.c index 0fc66fd..08816a9 100644 --- a/scalar_objects.c +++ b/scalar_objects.c @@ -82,10 +82,7 @@ static zval *get_object_zval_ptr_real( int type ) { if (op_type == IS_UNUSED) { - if (!SO_THIS) { - zend_error(E_ERROR, "Using $this when not in object context"); - } - + ZEND_ASSERT(SO_THIS && "Checked by get_object_zval_ptr_safe() beforehand"); return SO_THIS; } else { return get_zval_ptr_real(opline, op_type, node, execute_data, type); From 32066f9085052e9a0f9d27932e101f5f31d6d489 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 12 Nov 2023 12:44:29 +0100 Subject: [PATCH 09/11] Add PHP 8.2 and PHP 8.3 to CI --- .github/workflows/common.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index e854a8a..9d491b2 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -27,6 +27,8 @@ jobs: - "7.4" - "8.0" - "8.1" + - "8.2" + - "8.3" - "nightly" steps: - name: Setup PHP From 269d0f2bd6320435d8e0b5d6862f1a2e8f43242f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 13 Jul 2024 10:59:53 +0200 Subject: [PATCH 10/11] Add PHP 8.4 to CI matrix --- .github/workflows/common.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index 9d491b2..edbd8b6 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -29,6 +29,7 @@ jobs: - "8.1" - "8.2" - "8.3" + - "8.4" - "nightly" steps: - name: Setup PHP From 86dbcc0c939732faac93e3c5ea233205df142bf0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 10 Aug 2025 16:09:23 +0200 Subject: [PATCH 11/11] Add PHP 8.5 to CI matrix --- .github/workflows/common.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/common.yml b/.github/workflows/common.yml index edbd8b6..b446743 100644 --- a/.github/workflows/common.yml +++ b/.github/workflows/common.yml @@ -30,6 +30,7 @@ jobs: - "8.2" - "8.3" - "8.4" + - "8.5" - "nightly" steps: - name: Setup PHP