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
16 changes: 12 additions & 4 deletions lib/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6113,6 +6113,7 @@ private function emitQuietDimFetchChainPrefix(array $chain, Block $block): array
: null;
$op = new OpCode(OpCode::TYPE_ARRAY_DIM_FETCH, $resultSlot, $containerSlot, $dimSlot);
$op->arrayDimFetchIs = true;
$this->assignSourceMetadata($op, $fetch);
$opcodes[] = $op;
$containerSlot = $resultSlot;
}
Expand Down Expand Up @@ -14323,12 +14324,16 @@ protected function compileExpr(Op\Expr $expr, Block $block): array {
? OpCode::TYPE_ARRAY_DIM_FETCH_WRITE
: OpCode::TYPE_ARRAY_DIM_FETCH;

return array_merge($prefix, [new OpCode(
$fetchOp = new OpCode(
$fetchType,
$resultSlot,
$this->compileArrayDimFetchContainerSlot($expr, $block),
$dimSlot
)]);
);
// Zend attributes Undefined array key to the dim-fetch opline (#31994, zend_vm_def.h).
$this->assignSourceMetadata($fetchOp, $expr);

return array_merge($prefix, [$fetchOp]);
case Op\Expr\ConstFetch::class:
$nsName = null;
if (!is_null($expr->nsName)) {
Expand Down Expand Up @@ -16243,6 +16248,7 @@ private function compileArrayDimFetchRead(
null !== $fetch->dim ? $this->compileOperand($fetch->dim, $block, true) : null
);
$op->arrayDimFetchSkipFloatKeyDeprecation = $skipFloatKeyDeprecation;
$this->assignSourceMetadata($op, $fetch);
$block->addOpCode($op);
}

Expand All @@ -16252,12 +16258,14 @@ private function compileArrayDimFetchRead(
private function compileArrayDimFetchWrite(Op\Expr\ArrayDimFetch $fetch, Block $block): void
{
$this->rejectTemporaryExpressionInWriteContext($fetch->result, $block, $fetch);
$block->addOpCode(new OpCode(
$op = new OpCode(
OpCode::TYPE_ARRAY_DIM_FETCH_WRITE,
$this->compileOperand($fetch->result, $block, false),
$this->compileArrayDimFetchContainerSlot($fetch, $block),
null !== $fetch->dim ? $this->compileOperand($fetch->dim, $block, true) : null
));
);
$this->assignSourceMetadata($op, $fetch);
$block->addOpCode($op);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@
<file>./test/compliance/InheritedPropertyDefaults31895JITTest.php</file>
<file>./test/compliance/DynamicPropAssignWithGetNoSet31949VMTest.php</file>
<file>./test/compliance/DynamicPropAssignWithGetNoSet31949JITTest.php</file>
<file>./test/compliance/ListDestructUndefKeyLine31994VMTest.php</file>
<file>./test/compliance/ListDestructUndefKeyLine31994JITTest.php</file>
<file>./test/compliance/VarDumpUninitTypedProperty31147VMTest.php</file>
<file>./test/compliance/VarDumpUninitTypedProperty31147JITTest.php</file>
<file>./test/compliance/InOperatorPhpSrcReject31158VMTest.php</file>
Expand Down
32 changes: 32 additions & 0 deletions test/compliance/ListDestructUndefKeyLine31994JITTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

require_once __DIR__.'/../BaseTest.php';

/**
* JIT: keyed list destruct Undefined array key Warning cites list site (#31994).
*
* Dedicated provider — path-slash data-set names break --filter on full JITTest.
*
* @group llvm
*/
final class ListDestructUndefKeyLine31994JITTest extends BaseTest
{
protected static string $DIR = __DIR__;

public static function providePHPTests(): \Generator
{
yield 'list_destruct_undef_key_warning_line.phpt' => self::parsePHPT(
__DIR__.'/cases/language/list_destruct_undef_key_warning_line.phpt',
'list_destruct_undef_key_warning_line.phpt'
);
}

public function setUp(): void
{
$this->BIN = realpath(__DIR__.'/../../bin/jit.php');
}
}
30 changes: 30 additions & 0 deletions test/compliance/ListDestructUndefKeyLine31994VMTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

require_once __DIR__.'/../BaseTest.php';

/**
* VM: keyed list destruct Undefined array key Warning cites list site (#31994).
*
* Dedicated provider — path-slash data-set names break --filter on full VMTest.
*/
final class ListDestructUndefKeyLine31994VMTest extends BaseTest
{
protected static string $DIR = __DIR__;

public static function providePHPTests(): \Generator
{
yield 'list_destruct_undef_key_warning_line.phpt' => self::parsePHPT(
__DIR__.'/cases/language/list_destruct_undef_key_warning_line.phpt',
'list_destruct_undef_key_warning_line.phpt'
);
}

public function setUp(): void
{
$this->BIN = realpath(__DIR__.'/../../bin/vm.php');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Language: keyed list destructure Undefined array key Warning cites list site (#31994, zend_vm_def.h)
--FILE--
<?php
function warn_line(int $errno, string $message, string $file, int $line): bool
{
echo 'W:', $message, '@', $line, "\n";

return true;
}
set_error_handler('warn_line');

[$a, $b] = [1];
echo "a=$a\n";
['x' => $c] = ['y' => 1];
echo "c_done\n";
--EXPECT--
W:Undefined array key 1@10
a=1
W:Undefined array key "x"@12
c_done
Loading