Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Ast/PipeOperatorDesugar.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use PHPCompiler\CompilerVersion;

/**
* Desugar PHP 8.4+ pipe operator (|>) before nikic/php-parser (#3243, #7219).
* Desugar PHP 8.5+ pipe operator (|>) before nikic/php-parser (#3243, #7219, #22792).
*
* Lowering matches Zend: $lhs |> $callable(...) becomes $callable($lhs, ...).
* php-src: Zend/zend_compile.c pipe expression handling.
* php-src: Zend/zend_compile.c pipe expression handling (PHP 8.5+).
*/
final class PipeOperatorDesugar
{
Expand Down
8 changes: 4 additions & 4 deletions lib/CompilerVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,14 +895,14 @@ public static function supportsExitFunctionForm(): bool
}

/**
* PHP 8.4+ pipe operator (|>) — Zend/zend_language_parser.y (#7219, #12424, #16675).
* PHP 8.5+ pipe operator (|>) — Zend/zend_language_parser.y (#7219, #12424, #16675, #22792).
*
* Gated on stable 8.4.0 / {@see languageProfileVersion()} so 8.4.0-dev reference profile
* rejects |> like Zend 8.2. Forward profile via `PHP_COMPILER_PROFILE=8.4` enables desugar.
* Withheld on reference / PROFILE=8.4 (matches Zend 8.2 / 8.4 parse error). Enable via
* stable 8.5.0+ or explicit `PHP_COMPILER_PROFILE=8.5` forward profile.
*/
public static function supportsPipeOperator(): bool
{
return version_compare(self::languageProfileVersion(), '8.4.0', '>=');
return version_compare(self::languageProfileVersion(), '8.5.0', '>=');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/PipeOperatorSyntaxRejector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use PHPCompiler\Compiler\CompileFatal;

/**
* Reject PHP 8.4+ pipe operator (|>) on the Zend 8.2 reference profile (#12424, #18007).
* Reject PHP 8.5+ pipe operator (|>) below PROFILE=8.5 (#12424, #18007, #22792).
*
* Must run before {@see Ast\PipeOperatorDesugar} so pipe syntax is not lowered into valid PHP.
* php-src: Zend/zend_language_parser.y pipe expression grammar.
* php-src: Zend/zend_language_parser.y pipe expression grammar (PHP 8.5+).
*/
final class PipeOperatorSyntaxRejector
{
Expand Down
4 changes: 3 additions & 1 deletion test/compliance/JITTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1245,14 +1245,16 @@ public static function providePHPTests(): \Generator
&& !str_contains($name, 'try_catch_else_reference_profile')) {
continue;
}
// 8.4-target reject gate; skipped when pipe operator enabled (#12424, #18007).
// 8.5-target reject gate; skipped when pipe operator enabled (#12424, #18007, #22792).
// profile84_reject uses --ENV-- PROFILE=8.4 — always include.
if (CompilerVersion::supportsPipeOperator()
&& str_contains($name, 'pipe_operator_reference_profile')) {
continue;
}
if (!CompilerVersion::supportsPipeOperator()
&& str_contains($name, 'pipe_operator')
&& !str_contains($name, 'pipe_operator_reference_profile')
&& !str_contains($name, 'pipe_operator_profile84_reject')
&& !str_contains($name, 'pipe_operator_forward_profile')) {
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion test/compliance/VMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1187,14 +1187,16 @@ public static function providePHPTests(): \Generator
&& !str_contains($name, 'try_catch_else_reference_profile')) {
continue;
}
// 8.4-target reject gate; skipped when pipe operator enabled (#12424, #18007).
// 8.5-target reject gate; skipped when pipe operator enabled (#12424, #18007, #22792).
// profile84_reject uses --ENV-- PROFILE=8.4 — always include.
if (CompilerVersion::supportsPipeOperator()
&& str_contains($name, 'pipe_operator_reference_profile')) {
continue;
}
if (!CompilerVersion::supportsPipeOperator()
&& str_contains($name, 'pipe_operator')
&& !str_contains($name, 'pipe_operator_reference_profile')
&& !str_contains($name, 'pipe_operator_profile84_reject')
&& !str_contains($name, 'pipe_operator_forward_profile')) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
--TEST--
Language: pipe operator |> on forward profile PHP 8.4 (#16675, Zend/zend_language_parser.y)
Language: pipe operator |> on forward profile PHP 8.5 (#16675, #22792, Zend/zend_language_parser.y)
--SKIPIF--
<?php
if (!class_exists('PHPCompiler\\CompilerVersion')) {
require __DIR__ . '/../../../../vendor/autoload.php';
}
if (!PHPCompiler\CompilerVersion::supportsPipeOperator()) {
die('skip requires PHP 8.4+ pipe operator forward profile');
die('skip requires PHP 8.5+ pipe operator forward profile');
}
if (PHP_VERSION_ID < 80400) {
die('skip pipe operator requires PHP 8.4+ Zend for native PHPT');
if (PHP_VERSION_ID < 80500) {
die('skip pipe operator requires PHP 8.5+ Zend for native PHPT');
}
?>
--ENV--
PHP_COMPILER_PROFILE=8.4
PHP_COMPILER_PROFILE=8.5
--FILE--
<?php

Expand Down
16 changes: 16 additions & 0 deletions test/compliance/cases/language/pipe_operator_profile84_reject.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Language: pipe operator |> rejected on PROFILE=8.4 (#22792, Zend/zend_language_parser.y)
--SKIPIF--
<?php
if (!class_exists('PHPCompiler\\CompilerVersion')) {
require __DIR__ . '/../../../../vendor/autoload.php';
}
// Gate uses languageProfileVersion(); this case forces PROFILE=8.4 via --ENV--.
?>
--ENV--
PHP_COMPILER_PROFILE=8.4
--FILE--
<?php
echo "hello" |> strtoupper(...);
--EXPECT_EXIT--
255
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (!class_exists('PHPCompiler\\CompilerVersion')) {
require __DIR__ . '/../../../../vendor/autoload.php';
}
if (PHPCompiler\CompilerVersion::supportsPipeOperator()) {
die('skip pipe operator enabled on PHP 8.4.0+ target');
die('skip pipe operator enabled on PHP 8.5.0+ target');
}
?>
--FILE--
Expand Down
17 changes: 16 additions & 1 deletion test/unit/CompilerVersionGateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1245,10 +1245,25 @@ public function testSupportsPipeOperatorFalseOnReferenceProfile(): void
$this->assertFalse(CompilerVersion::supportsPipeOperator());
}

public function testSupportsPipeOperatorTrueWhenProfile84(): void
public function testSupportsPipeOperatorFalseWhenProfile84(): void
{
$prev = getenv('PHP_COMPILER_PROFILE');
putenv('PHP_COMPILER_PROFILE=8.4');
try {
$this->assertFalse(CompilerVersion::supportsPipeOperator());
} finally {
if (false === $prev) {
putenv('PHP_COMPILER_PROFILE');
} else {
putenv('PHP_COMPILER_PROFILE='.$prev);
}
}
}

public function testSupportsPipeOperatorTrueWhenProfile85(): void
{
$prev = getenv('PHP_COMPILER_PROFILE');
putenv('PHP_COMPILER_PROFILE=8.5');
try {
$this->assertTrue(CompilerVersion::supportsPipeOperator());
} finally {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/PipeOperatorReferenceProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testSupportsPipeOperatorFalseOnReferenceProfile(): void
public function testDesugarNoOpWhenPipeDisabled(): void
{
if (CompilerVersion::supportsPipeOperator()) {
$this->markTestSkipped('pipe operator enabled on PHP 8.4.0+ target');
$this->markTestSkipped('pipe operator enabled on PHP 8.5.0+ target');
}
$src = '<?php $x = 5 |> fn ($v) => $v * 2;';
$this->assertSame($src, PipeOperatorDesugar::desugar($src));
Expand Down
6 changes: 3 additions & 3 deletions test/unit/PipeOperatorSyntaxRejectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class PipeOperatorSyntaxRejectorTest extends TestCase
public function testRejectsPipeOnReferenceProfile(): void
{
if (CompilerVersion::supportsPipeOperator()) {
self::markTestSkipped('pipe operator enabled on PHP 8.4.0+ target');
self::markTestSkipped('pipe operator enabled on PHP 8.5.0+ target');
}

$this->expectException(CompileFatal::class);
Expand All @@ -26,7 +26,7 @@ public function testRejectsPipeOnReferenceProfile(): void
public function testReferenceProfileSyntaxErrorLine(): void
{
if (CompilerVersion::supportsPipeOperator()) {
self::markTestSkipped('pipe operator enabled on PHP 8.4.0+ target');
self::markTestSkipped('pipe operator enabled on PHP 8.5.0+ target');
}

$error = PipeOperatorDesugar::referenceProfileSyntaxError(<<<'PHP'
Expand All @@ -43,7 +43,7 @@ public function testReferenceProfileSyntaxErrorLine(): void
public function testNoOpWithoutPipeToken(): void
{
if (CompilerVersion::supportsPipeOperator()) {
self::markTestSkipped('pipe operator enabled on PHP 8.4.0+ target');
self::markTestSkipped('pipe operator enabled on PHP 8.5.0+ target');
}

$code = '<?php echo 1 + 2;';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/PipeOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PHPCompiler\Ast\PipeOperatorDesugar;
use PHPUnit\Framework\TestCase;

/** PHP 8.4+ pipe operator (|>) VM desugar (#3243, #7219). */
/** PHP 8.5+ pipe operator (|>) VM desugar (#3243, #7219, #22792). */
final class PipeOperatorTest extends TestCase
{
protected function setUp(): void
Expand Down