packages/deriver/tests/Unit/Deriver/Evaluator/Execution/Offset/ProtocolTest.php

1<?php
2
3declare (strict_types=1);
4
5namespace Tests\Unit\Deriver\Evaluator\Execution\Offset;
6
7use Deriver\Deriver;
8use Deriver\Deriver\Candidate\ResultRef;
9use Deriver\Deriver\Candidate\Snapshot;
10use Deriver\Deriver\Candidate\Statistics;
11use Deriver\Deriver\Contributions;
12use Deriver\Deriver\DeriverConfig;
13use Deriver\Deriver\Evaluator\Call\BoundInstruction;
14use Deriver\Deriver\Evaluator\Call\Evaluators;
15use Deriver\Deriver\Evaluator\Call\Extensions;
16use Deriver\Deriver\Evaluator\Call\Registrations;
17use Deriver\Deriver\Evaluator\Call\StateRegistry;
18use Deriver\Deriver\Evaluator\EvaluatorConfig;
19use Deriver\Deriver\Evaluator\Evidence\Frontier;
20use Deriver\Deriver\Evaluator\Execution\Call\Allocation;
21use Deriver\Deriver\Evaluator\Execution\Call\ArgumentBinding;
22use Deriver\Deriver\Evaluator\Execution\Call\ArgumentOrder;
23use Deriver\Deriver\Evaluator\Execution\Call\CallableCheck;
24use Deriver\Deriver\Evaluator\Execution\Call\CallExecutor;
25use Deriver\Deriver\Evaluator\Execution\Call\CallResolution;
26use Deriver\Deriver\Evaluator\Execution\Call\Creation\Access;
27use Deriver\Deriver\Evaluator\Execution\Call\Member\Invocation;
28use Deriver\Deriver\Evaluator\Execution\Call\Native\Invocation as NativeInvocation;
29use Deriver\Deriver\Evaluator\Execution\Call\Native\Signatures;
30use Deriver\Deriver\Evaluator\Execution\Call\ParameterBinding;
31use Deriver\Deriver\Evaluator\Execution\Call\PassedArgument;
32use Deriver\Deriver\Evaluator\Execution\Call\Preparation\Creation;
33use Deriver\Deriver\Evaluator\Execution\Call\Preparation\Resolution;
34use Deriver\Deriver\Evaluator\Execution\Call\Preparation\Target;
35use Deriver\Deriver\Evaluator\Execution\Call\Preparation\Transfer;
36use Deriver\Deriver\Evaluator\Execution\Call\TypeBinding;
37use Deriver\Deriver\Evaluator\Execution\Call\TypeCheck;
38use Deriver\Deriver\Evaluator\Execution\Completion\Alternative;
39use Deriver\Deriver\Evaluator\Execution\Completion\Assessment;
40use Deriver\Deriver\Evaluator\Execution\Completion\Completion;
41use Deriver\Deriver\Evaluator\Execution\Completion\Exceptional;
42use Deriver\Deriver\Evaluator\Execution\Completion\StorageSnapshot;
43use Deriver\Deriver\Evaluator\Execution\Constraints;
44use Deriver\Deriver\Evaluator\Execution\Context;
45use Deriver\Deriver\Evaluator\Execution\Control\ExceptionMatch;
46use Deriver\Deriver\Evaluator\Execution\Control\ObservationLimit;
47use Deriver\Deriver\Evaluator\Execution\Control\StateJoin;
48use Deriver\Deriver\Evaluator\Execution\Control\Unwinding;
49use Deriver\Deriver\Evaluator\Execution\Demand\Discovery;
50use Deriver\Deriver\Evaluator\Execution\Dependencies;
51use Deriver\Deriver\Evaluator\Execution\Evaluator;
52use Deriver\Deriver\Evaluator\Execution\EvaluatorConfig as ExecutionEvaluatorConfig;
53use Deriver\Deriver\Evaluator\Execution\InstructionTransfer;
54use Deriver\Deriver\Evaluator\Execution\Memory\Location;
55use Deriver\Deriver\Evaluator\Execution\Memory\Materialization;
56use Deriver\Deriver\Evaluator\Execution\Memory\Memory;
57use Deriver\Deriver\Evaluator\Execution\Memory\ReferenceConstraint;
58use Deriver\Deriver\Evaluator\Execution\Memory\Slots\SlotReference;
59use Deriver\Deriver\Evaluator\Execution\Memory\Slots\StateStorage;
60use Deriver\Deriver\Evaluator\Execution\Memory\StorageCapture;
61use Deriver\Deriver\Evaluator\Execution\ObservationCollector;
62use Deriver\Deriver\Evaluator\Execution\Offset\Address;
63use Deriver\Deriver\Evaluator\Execution\Offset\Path;
64use Deriver\Deriver\Evaluator\Execution\Offset\Protocol;
65use Deriver\Deriver\Evaluator\Execution\Offset\ProtocolAccess;
66use Deriver\Deriver\Evaluator\Execution\Offset\Reader;
67use Deriver\Deriver\Evaluator\Execution\Offset\Strings;
68use Deriver\Deriver\Evaluator\Execution\Offset\Transfer as OffsetTransfer;
69use Deriver\Deriver\Evaluator\Execution\Operation\Conversions;
70use Deriver\Deriver\Evaluator\Execution\Operation\ScalarErrors;
71use Deriver\Deriver\Evaluator\Execution\State;
72use Deriver\Deriver\Evaluator\Execution\Summary\Evaluation;
73use Deriver\Deriver\Evaluator\Execution\Summary\Isolation;
74use Deriver\Deriver\Evaluator\Execution\Trace\Derivation;
75use Deriver\Deriver\Evaluator\Execution\Transfer\CompoundAssignment;
76use Deriver\Deriver\Evaluator\Execution\Transfer\MemoryStep;
77use Deriver\Deriver\Evaluator\Execution\Transfer\ObjectAccess;
78use Deriver\Deriver\Evaluator\Execution\Transfer\PropertyAccessCheck;
79use Deriver\Deriver\Evaluator\Execution\Transfer\PropertyLookup;
80use Deriver\Deriver\Evaluator\Execution\Transfer\PropertyReference;
81use Deriver\Deriver\Evaluator\Execution\Transfer\PropertySlot;
82use Deriver\Deriver\Evaluator\Execution\Transfer\PropertyTransfer;
83use Deriver\Deriver\Evaluator\Execution\Transfer\PureStep;
84use Deriver\Deriver\Evaluator\Execution\Transfer\ReferenceAssignment;
85use Deriver\Deriver\Evaluator\Request\Budget;
86use Deriver\Deriver\Evaluator\Request\EntryPoint;
87use Deriver\Deriver\Evaluator\Request\QueryScope;
88use Deriver\Deriver\Evaluator\Request\ReturnQuery;
89use Deriver\Deriver\Evaluator\Scalar\Arithmetic;
90use Deriver\Deriver\Evaluator\Scalar\Arrays;
91use Deriver\Deriver\Evaluator\Scalar\Comparison;
92use Deriver\Deriver\Evaluator\Scalar\Identity;
93use Deriver\Deriver\Evaluator\Scalar\Increment;
94use Deriver\Deriver\Evaluator\Scalar\Operations;
95use Deriver\Deriver\Evaluator\TargetProfile;
96use Deriver\Deriver\Evaluator\Term;
97use Deriver\Deriver\Evaluator\TermKind;
98use Deriver\Deriver\Execution\DerivationResult;
99use Deriver\Deriver\Execution\QueryExecution;
100use Deriver\Deriver\Execution\ResultAssessment;
101use Deriver\Deriver\Identity\QueryEncoding;
102use Deriver\Deriver\Identity\ValueGraph;
103use Deriver\Deriver\Lowerer\AggregateLowering;
104use Deriver\Deriver\Lowerer\AssignmentLowering;
105use Deriver\Deriver\Lowerer\CallLowering;
106use Deriver\Deriver\Lowerer\Control\ConditionalLowering;
107use Deriver\Deriver\Lowerer\Control\DestructuringLowering;
108use Deriver\Deriver\Lowerer\Declaration\CallableIdentity;
109use Deriver\Deriver\Lowerer\Declaration\CallableSource;
110use Deriver\Deriver\Lowerer\Declaration\ConstantSignatures;
111use Deriver\Deriver\Lowerer\Declaration\Index;
112use Deriver\Deriver\Lowerer\Declaration\Indexer;
113use Deriver\Deriver\Lowerer\Declaration\Metadata\ClassDeclaration;
114use Deriver\Deriver\Lowerer\Declaration\Metadata\PropertyDeclaration;
115use Deriver\Deriver\Lowerer\Declaration\Traits\Composition;
116use Deriver\Deriver\Lowerer\EffectInspection;
117use Deriver\Deriver\Lowerer\ExpressionLowering;
118use Deriver\Deriver\Lowerer\Graph\BasicBlock;
119use Deriver\Deriver\Lowerer\Graph\CallableGraph;
120use Deriver\Deriver\Lowerer\Graph\Instruction;
121use Deriver\Deriver\Lowerer\Graph\Parameter;
122use Deriver\Deriver\Lowerer\Graph\Terminator;
123use Deriver\Deriver\Lowerer\Hierarchy\Access as HierarchyAccess;
124use Deriver\Deriver\Lowerer\Hierarchy\Builtins;
125use Deriver\Deriver\Lowerer\Hierarchy\Dispatch;
126use Deriver\Deriver\Lowerer\InstructionEmitter;
127use Deriver\Deriver\Lowerer\Lowerer;
128use Deriver\Deriver\Lowerer\LoweringScope;
129use Deriver\Deriver\Lowerer\StatementLowering;
130use Deriver\Deriver\MicroEvaluatorConversion;
131use Deriver\Deriver\Parser\Node\File;
132use Deriver\Deriver\Parser\Parser;
133use Deriver\Deriver\Parser\ParserConfig;
134use Deriver\Deriver\Parser\TargetSyntax;
135use Deriver\Deriver\Providers\ProviderExpansion;
136use Deriver\Deriver\Resolver\AssignmentPatterns;
137use Deriver\Deriver\Resolver\ClassScope;
138use Deriver\Deriver\Resolver\ExpressionValidation;
139use Deriver\Deriver\Resolver\MagicContext;
140use Deriver\Deriver\Resolver\Resolver;
141use Deriver\Deriver\Selection\QueryValidation;
142use Deriver\Deriver\SnapshotIdentity;
143use Deriver\Deriver\Sources\LineMap;
144use Deriver\Deriver\Sources\Path as SourcesPath;
145use Deriver\Deriver\Sources\Source;
146use Deriver\Deriver\Sources\SourceRef;
147use Deriver\Deriver\Sources\Sources;
148use Deriver\Exception\ParserException;
149use Deriver\Exception\ResolutionException;
150use JsonException;
151use PHPUnit\Framework\Attributes\CoversClass;
152use PHPUnit\Framework\Attributes\DataProvider;
153use PHPUnit\Framework\Attributes\Small;
154use PHPUnit\Framework\Attributes\UsesClass;
155use PHPUnit\Framework\TestCase;
156
157/**
158 * @covers \Deriver\Deriver\Evaluator\Execution\Offset\Protocol
159 */
160#[UsesClass(Resolver::class)]
161#[UsesClass(ExpressionValidation::class)]
162#[UsesClass(ResolutionException::class)]
163#[UsesClass(ParserConfig::class)]
164#[UsesClass(ParserException::class)]
165#[CoversClass(Protocol::class)]
166#[UsesClass(QueryExecution::class)]
167#[UsesClass(QueryValidation::class)]
168#[UsesClass(ResultAssessment::class)]
169#[UsesClass(Deriver::class)]
170#[UsesClass(Constraints::class)]
171#[UsesClass(BasicBlock::class)]
172#[UsesClass(CallableGraph::class)]
173#[UsesClass(CallableIdentity::class)]
174#[UsesClass(ClassDeclaration::class)]
175#[UsesClass(Instruction::class)]
176#[UsesClass(Parameter::class)]
177#[UsesClass(PropertyDeclaration::class)]
178#[UsesClass(Terminator::class)]
179#[UsesClass(Allocation::class)]
180#[UsesClass(ArgumentBinding::class)]
181#[UsesClass(ArgumentOrder::class)]
182#[UsesClass(CallExecutor::class)]
183#[UsesClass(CallResolution::class)]
184#[UsesClass(CallableCheck::class)]
185#[UsesClass(Access::class)]
186#[UsesClass(Builtins::class)]
187#[UsesClass(Dispatch::class)]
188#[UsesClass(HierarchyAccess::class)]
189#[UsesClass(Invocation::class)]
190#[UsesClass(NativeInvocation::class)]
191#[UsesClass(Signatures::class)]
192#[UsesClass(ParameterBinding::class)]
193#[UsesClass(PassedArgument::class)]
194#[UsesClass(Creation::class)]
195#[UsesClass(Resolution::class)]
196#[UsesClass(Target::class)]
197#[UsesClass(Transfer::class)]
198#[UsesClass(TypeBinding::class)]
199#[UsesClass(TypeCheck::class)]
200#[UsesClass(Completion::class)]
201#[UsesClass(Context::class)]
202#[UsesClass(ExceptionMatch::class)]
203#[UsesClass(ObservationLimit::class)]
204#[UsesClass(StateJoin::class)]
205#[UsesClass(Unwinding::class)]
206#[UsesClass(Discovery::class)]
207#[UsesClass(Dependencies::class)]
208#[UsesClass(InstructionTransfer::class)]
209#[UsesClass(Evaluator::class)]
210#[UsesClass(SlotReference::class)]
211#[UsesClass(StateStorage::class)]
212#[UsesClass(ObservationCollector::class)]
213#[UsesClass(Address::class)]
214#[UsesClass(Path::class)]
215#[UsesClass(ProtocolAccess::class)]
216#[UsesClass(Reader::class)]
217#[UsesClass(Strings::class)]
218#[UsesClass(OffsetTransfer::class)]
219#[UsesClass(Conversions::class)]
220#[UsesClass(ScalarErrors::class)]
221#[UsesClass(State::class)]
222#[UsesClass(Evaluation::class)]
223#[UsesClass(Isolation::class)]
224#[UsesClass(CompoundAssignment::class)]
225#[UsesClass(MemoryStep::class)]
226#[UsesClass(ObjectAccess::class)]
227#[UsesClass(PropertyAccessCheck::class)]
228#[UsesClass(PropertyLookup::class)]
229#[UsesClass(PropertyReference::class)]
230#[UsesClass(PropertySlot::class)]
231#[UsesClass(PropertyTransfer::class)]
232#[UsesClass(PureStep::class)]
233#[UsesClass(ReferenceAssignment::class)]
234#[UsesClass(Location::class)]
235#[UsesClass(Materialization::class)]
236#[UsesClass(Memory::class)]
237#[UsesClass(ReferenceConstraint::class)]
238#[UsesClass(StorageCapture::class)]
239#[UsesClass(Extensions::class)]
240#[UsesClass(ProviderExpansion::class)]
241#[UsesClass(Evaluators::class)]
242#[UsesClass(StateRegistry::class)]
243#[UsesClass(DeriverConfig::class)]
244#[UsesClass(EntryPoint::class)]
245#[UsesClass(Sources::class)]
246#[UsesClass(SourcesPath::class)]
247#[UsesClass(Snapshot::class)]
248#[UsesClass(Source::class)]
249#[UsesClass(TargetProfile::class)]
250#[UsesClass(Budget::class)]
251#[UsesClass(QueryScope::class)]
252#[UsesClass(ReturnQuery::class)]
253#[UsesClass(ResultRef::class)]
254#[UsesClass(SourceRef::class)]
255#[UsesClass(Alternative::class)]
256#[UsesClass(Assessment::class)]
257#[UsesClass(Derivation::class)]
258#[UsesClass(DerivationResult::class)]
259#[UsesClass(Exceptional::class)]
260#[UsesClass(Frontier::class)]
261#[UsesClass(QueryEncoding::class)]
262#[UsesClass(ValueGraph::class)]
263#[UsesClass(Statistics::class)]
264#[UsesClass(StorageSnapshot::class)]
265#[UsesClass(Parser::class)]
266#[UsesClass(File::class)]
267#[UsesClass(AggregateLowering::class)]
268#[UsesClass(AssignmentLowering::class)]
269#[UsesClass(CallLowering::class)]
270#[UsesClass(Lowerer::class)]
271#[UsesClass(ConditionalLowering::class)]
272#[UsesClass(DestructuringLowering::class)]
273#[UsesClass(EffectInspection::class)]
274#[UsesClass(ExpressionLowering::class)]
275#[UsesClass(InstructionEmitter::class)]
276#[UsesClass(LoweringScope::class)]
277#[UsesClass(StatementLowering::class)]
278#[UsesClass(ConstantSignatures::class)]
279#[UsesClass(CallableSource::class)]
280#[UsesClass(Indexer::class)]
281#[UsesClass(Index::class)]
282#[UsesClass(Composition::class)]
283#[UsesClass(LineMap::class)]
284#[UsesClass(MagicContext::class)]
285#[UsesClass(AssignmentPatterns::class)]
286#[UsesClass(ClassScope::class)]
287#[UsesClass(TargetSyntax::class)]
288#[UsesClass(Arithmetic::class)]
289#[UsesClass(Arrays::class)]
290#[UsesClass(Comparison::class)]
291#[UsesClass(Identity::class)]
292#[UsesClass(Increment::class)]
293#[UsesClass(Operations::class)]
294#[UsesClass(Term::class)]
295#[Small]
296final class ProtocolTest extends TestCase
297{
298    public function testApplyReturnsAssignmentValueAfterOffsetSet(): void
299    {
300        $source = '<?php class Box implements ArrayAccess {public mixed $value=0;function offsetGet($key){return $key;}function offsetExists($key){return $key === "yes";}function offsetSet($key,$value){$this->value=$value;}function offsetUnset($key){$this->value=null;}}function target(){}';
301        $budget = new Budget();
302        $configuration = new DeriverConfig();
303        $contributions = new Contributions();
304        $input = new Sources([new Source('fixture.php', $source)]);
305        $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
306        $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
307        $contributions1 = $providers->contributions;
308        $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
309        $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
310        $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
311        $snapshotId = $identity->id;
312        $input1 = $providers->input;
313        $parser = new Parser(new ParserConfig($target->version));
314        $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(SourcesPath::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
315        $program1 = new Index($snapshotId, $trees);
316        $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
317        $snapshotId1 = 'test';
318        $input2 = new Sources([new Source('fixture.php', $source)]);
319        $profile = $execution->configuration->target;
320        $parser1 = new Parser(new ParserConfig($profile->version));
321        $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(SourcesPath::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
322        $program = new Index($snapshotId1, $trees1);
323        $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
324        $body = $context->program->callable('target');
325        self::assertNotNull($body);
326        $state = new State();
327        $state->memory->cells['object:box'] = Term::array(['value' => Term::constant(0)]);
328        $state->memory->classes['box'] = 'Box';
329        $receiver = new Term(TermKind::Object, 'box', attributes: ['class' => 'Box']);
330        $access = new ProtocolAccess($receiver, Term::constant('yes'));
331        $protocol = new Protocol(new Evaluator($context));
332        $state->registers['rhs'] = Term::constant(7);
333        $instruction = new BoundInstruction('write', 'write', $body->source, 'result', ['slot', 'rhs']);
334        $paths = $protocol->apply($body, $instruction, $state, $access);
335        self::assertCount(1, $paths);
336        self::assertSame(7, $paths[0]->value('result')->native());
337        self::assertSame(7, $paths[0]->memory->read(new Location('object:box', ['value']))->native());
338    }
339    public function testCallPreservesOriginalArrayKeysForUserMethods(): void
340    {
341        $source = '<?php class Box implements ArrayAccess {public mixed $value=0;function offsetGet($key){return $key;}function offsetExists($key){return $key === "yes";}function offsetSet($key,$value){$this->value=$value;}function offsetUnset($key){$this->value=null;}}function target(){}';
342        $budget = new Budget();
343        $configuration = new DeriverConfig();
344        $contributions = new Contributions();
345        $input = new Sources([new Source('fixture.php', $source)]);
346        $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
347        $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
348        $contributions1 = $providers->contributions;
349        $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
350        $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
351        $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
352        $snapshotId = $identity->id;
353        $input1 = $providers->input;
354        $parser = new Parser(new ParserConfig($target->version));
355        $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(SourcesPath::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
356        $program1 = new Index($snapshotId, $trees);
357        $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
358        $snapshotId1 = 'test';
359        $input2 = new Sources([new Source('fixture.php', $source)]);
360        $profile = $execution->configuration->target;
361        $parser1 = new Parser(new ParserConfig($profile->version));
362        $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(SourcesPath::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
363        $program = new Index($snapshotId1, $trees1);
364        $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
365        $body = $context->program->callable('target');
366        self::assertNotNull($body);
367        $state = new State();
368        $state->memory->cells['object:box'] = Term::array(['value' => Term::constant(0)]);
369        $state->memory->classes['box'] = 'Box';
370        $receiver = new Term(TermKind::Object, 'box', attributes: ['class' => 'Box']);
371        $access = new ProtocolAccess($receiver, Term::constant('yes'));
372        $protocol = new Protocol(new Evaluator($context));
373        $instruction = new BoundInstruction('get', 'read', $body->source, 'result', ['slot']);
374        $paths = $protocol->call($body, $instruction, $state, $access, 'offsetGet', [new PassedArgument(Term::array([Term::constant(2)]))]);
375        self::assertSame([2], $paths[0]->value('result')->native());
376    }
377    public function testGetReturnsTheSourceMethodResult(): void
378    {
379        $source = '<?php class Box implements ArrayAccess {public mixed $value=0;function offsetGet($key){return $key;}function offsetExists($key){return $key === "yes";}function offsetSet($key,$value){$this->value=$value;}function offsetUnset($key){$this->value=null;}}function target(){}';
380        $budget = new Budget();
381        $configuration = new DeriverConfig();
382        $contributions = new Contributions();
383        $input = new Sources([new Source('fixture.php', $source)]);
384        $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
385        $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
386        $contributions1 = $providers->contributions;
387        $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
388        $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
389        $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
390        $snapshotId = $identity->id;
391        $input1 = $providers->input;
392        $parser = new Parser(new ParserConfig($target->version));
393        $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(SourcesPath::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
394        $program1 = new Index($snapshotId, $trees);
395        $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
396        $snapshotId1 = 'test';
397        $input2 = new Sources([new Source('fixture.php', $source)]);
398        $profile = $execution->configuration->target;
399        $parser1 = new Parser(new ParserConfig($profile->version));
400        $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(SourcesPath::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
401        $program = new Index($snapshotId1, $trees1);
402        $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
403        $body = $context->program->callable('target');
404        self::assertNotNull($body);
405        $state = new State();
406        $state->memory->cells['object:box'] = Term::array(['value' => Term::constant(0)]);
407        $state->memory->classes['box'] = 'Box';
408        $receiver = new Term(TermKind::Object, 'box', attributes: ['class' => 'Box']);
409        $access = new ProtocolAccess($receiver, Term::constant('yes'));
410        $protocol = new Protocol(new Evaluator($context));
411        $instruction = new BoundInstruction('get', 'read', $body->source, 'result', ['slot']);
412        $paths = $protocol->get($body, $instruction, $state, $access);
413        self::assertSame('yes', $paths[0]->value('result')->native());
414    }
415    public function testSilentDistinguishesExistenceFromCoalescingReads(): void
416    {
417        $source = '<?php class Box implements ArrayAccess {public mixed $value=0;function offsetGet($key){return $key;}function offsetExists($key){return $key === "yes";}function offsetSet($key,$value){$this->value=$value;}function offsetUnset($key){$this->value=null;}}function target(){}';
418        $budget = new Budget();
419        $configuration = new DeriverConfig();
420        $contributions = new Contributions();
421        $input = new Sources([new Source('fixture.php', $source)]);
422        $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
423        $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
424        $contributions1 = $providers->contributions;
425        $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
426        $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
427        $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
428        $snapshotId = $identity->id;
429        $input1 = $providers->input;
430        $parser = new Parser(new ParserConfig($target->version));
431        $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(SourcesPath::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
432        $program1 = new Index($snapshotId, $trees);
433        $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
434        $snapshotId1 = 'test';
435        $input2 = new Sources([new Source('fixture.php', $source)]);
436        $profile = $execution->configuration->target;
437        $parser1 = new Parser(new ParserConfig($profile->version));
438        $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(SourcesPath::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
439        $program = new Index($snapshotId1, $trees1);
440        $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
441        $body = $context->program->callable('target');
442        self::assertNotNull($body);
443        $state = new State();
444        $state->memory->cells['object:box'] = Term::array(['value' => Term::constant(0)]);
445        $state->memory->classes['box'] = 'Box';
446        $receiver = new Term(TermKind::Object, 'box', attributes: ['class' => 'Box']);
447        $access = new ProtocolAccess($receiver, Term::constant('yes'));
448        $protocol = new Protocol(new Evaluator($context));
449        $probe = new BoundInstruction('exists', 'read-silent', $body->source, 'result', ['slot'], attributes: ['existence' => true]);
450        $read = new BoundInstruction('coalesce', 'read-silent', $body->source, 'result', ['slot']);
451        self::assertTrue($protocol->silent($body, $probe, $state->fork(), $access)[0]->value('result')->native());
452        self::assertSame('yes', $protocol->silent($body, $read, $state->fork(), $access)[0]->value('result')->native());
453    }
454    public function testIndirectCreatesTemporaryReferencesForValueReturns(): void
455    {
456        $source = '<?php class Box implements ArrayAccess {public mixed $value=0;function offsetGet($key){return $key;}function offsetExists($key){return $key === "yes";}function offsetSet($key,$value){$this->value=$value;}function offsetUnset($key){$this->value=null;}}function target(){}';
457        $budget = new Budget();
458        $configuration = new DeriverConfig();
459        $contributions = new Contributions();
460        $input = new Sources([new Source('fixture.php', $source)]);
461        $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
462        $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
463        $contributions1 = $providers->contributions;
464        $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
465        $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
466        $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
467        $snapshotId = $identity->id;
468        $input1 = $providers->input;
469        $parser = new Parser(new ParserConfig($target->version));
470        $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(SourcesPath::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
471        $program1 = new Index($snapshotId, $trees);
472        $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
473        $snapshotId1 = 'test';
474        $input2 = new Sources([new Source('fixture.php', $source)]);
475        $profile = $execution->configuration->target;
476        $parser1 = new Parser(new ParserConfig($profile->version));
477        $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(SourcesPath::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
478        $program = new Index($snapshotId1, $trees1);
479        $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
480        $body = $context->program->callable('target');
481        self::assertNotNull($body);
482        $state = new State();
483        $state->memory->cells['object:box'] = Term::array(['value' => Term::constant(0)]);
484        $state->memory->classes['box'] = 'Box';
485        $receiver = new Term(TermKind::Object, 'box', attributes: ['class' => 'Box']);
486        $access = new ProtocolAccess($receiver, Term::constant('yes'));
487        $protocol = new Protocol(new Evaluator($context));
488        $state->registers['result'] = Term::constant(4);
489        $instruction = new BoundInstruction('reference', 'reference', $body->source, 'result', ['slot']);
490        $paths = $protocol->indirect($body, $instruction, $state, $access);
491        self::assertSame(TermKind::Cell, $paths[0]->registers['result']->kind);
492        self::assertSame(4, $paths[0]->value('result')->native());
493        self::assertSame(['PHP_WARNING'], array_column(array_values($context->frontiers), 'code'));
494    }
495    public function testNestedContinuesFromTheReturnedReferenceCell(): void
496    {
497        $source = '<?php class Box implements ArrayAccess {public mixed $value=0;function offsetGet($key){return $key;}function offsetExists($key){return $key === "yes";}function offsetSet($key,$value){$this->value=$value;}function offsetUnset($key){$this->value=null;}}function target(){}';
498        $budget = new Budget();
499        $configuration = new DeriverConfig();
500        $contributions = new Contributions();
501        $input = new Sources([new Source('fixture.php', $source)]);
502        $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
503        $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
504        $contributions1 = $providers->contributions;
505        $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
506        $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
507        $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
508        $snapshotId = $identity->id;
509        $input1 = $providers->input;
510        $parser = new Parser(new ParserConfig($target->version));
511        $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(SourcesPath::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
512        $program1 = new Index($snapshotId, $trees);
513        $execution = new QueryExecution($program1, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program1->diagnostics())));
514        $snapshotId1 = 'test';
515        $input2 = new Sources([new Source('fixture.php', $source)]);
516        $profile = $execution->configuration->target;
517        $parser1 = new Parser(new ParserConfig($profile->version));
518        $trees1 = array_map(static fn (Source $source2): File => (new Resolver())->resolve($parser1->parse(new Source(SourcesPath::normalize($source2->path), $source2->contents, $source2->declarationsOnly))), iterator_to_array($input2, false));
519        $program = new Index($snapshotId1, $trees1);
520        $context = new Context($program, new ReturnQuery('target', budget: $budget), $execution->configuration, $execution->evaluators);
521        $body = $context->program->callable('target');
522        self::assertNotNull($body);
523        $state = new State();
524        $state->memory->cells['object:box'] = Term::array(['value' => Term::constant(0)]);
525        $state->memory->classes['box'] = 'Box';
526        $receiver = new Term(TermKind::Object, 'box', attributes: ['class' => 'Box']);
527        $access = new ProtocolAccess($receiver, Term::constant('yes'));
528        $protocol = new Protocol(new Evaluator($context));
529        $location = $state->memory->allocate(Term::array([Term::constant(8)]));
530        $state->offsets['slot'] = new Address('outer', Term::constant(0));
531        $nested = new ProtocolAccess($receiver, Term::constant('x'), ['slot']);
532        $instruction = new BoundInstruction('nested', 'read', $body->source, 'result', ['slot']);
533        $paths = $protocol->nested($body, $instruction, $state, $nested, $location);
534        self::assertSame(8, $paths[0]->value('result')->native());
535    }
536    /**
537     * @throws JsonException If recorded engine observations cannot be decoded
538     */
539    #[DataProvider('providerArrayAccessSemantics')]
540    public function testApplyPreservesRecordedArrayAccessValuesEffectsAndExceptions(string $source, string $normalJson, string $exception, bool $diagnostic): void
541    {
542        $expected = json_decode($normalJson, true, 512, JSON_THROW_ON_ERROR);
543        $symbol = 'target';
544        $input = new Sources([new Source('fixture.php', $source)]);
545        $configuration = new DeriverConfig();
546        $contributions = new Contributions();
547        $target = new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision);
548        $providers = new ProviderExpansion($input, array_map(Term::fromNative(...), $configuration->environment), $contributions);
549        $contributions1 = $providers->contributions;
550        $evaluators = new Evaluators(new TargetProfile($configuration->phpVersion, $configuration->integerBits, $configuration->floatPrecision), new Registrations($contributions1->evaluators, $contributions1->providers, $contributions1->domains, $contributions1->intrinsics, $contributions1->stateSlots), $configuration->standardEvaluators);
551        $settings = new EvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators, array_map((new MicroEvaluatorConversion())->convert(...), $configuration->evaluators));
552        $identity = new SnapshotIdentity($providers->input, $settings, $evaluators, $providers->manifest);
553        $snapshotId = $identity->id;
554        $input1 = $providers->input;
555        $parser = new Parser(new ParserConfig($target->version));
556        $trees = array_map(static fn (Source $source1): File => (new Resolver())->resolve($parser->parse(new Source(SourcesPath::normalize($source1->path), $source1->contents, $source1->declarationsOnly))), iterator_to_array($input1, false));
557        $program = new Index($snapshotId, $trees);
558        $result = (new QueryExecution($program, new ExecutionEvaluatorConfig($target, $providers->environment, $configuration->standardEvaluators), $evaluators, $identity->snapshot(array_map(Frontier::fromDiagnostic(...), $program->diagnostics()))))->derive(new ReturnQuery($symbol));
559        self::assertSame($expected, array_map(static fn (Alternative $outcome) => $outcome->values['return']->native(), $result->normalOutcomes));
560        self::assertSame($exception === '' ? [] : [$exception], array_map(static fn (Exceptional $outcome): int|float|string|bool|null => $outcome->exception->literal, $result->exceptionalOutcomes));
561        self::assertSame($diagnostic, in_array('PHP_WARNING', array_column($result->frontiers, 'code'), true));
562        self::assertSame([], array_diff(array_column($result->frontiers, 'code'), ['PHP_WARNING']));
563    }
564    /**
565     * @return iterable<string,array{string,string,string,bool}>
566     */
567    public static function providerArrayAccessSemantics(): iterable
568    {
569        foreach (['intWrite' => ['<?php function target(){$a=4;try{$a[0]=2;}catch(Error $e){return $a;}return 999;}', '[4]', '', false], 'nullWrite' => ['<?php function target(){$a=null;$a[0]=2;return $a;}', '[[2]]', '', false], 'falseWrite' => ['<?php function target(){$a=false;$a[0]=2;return $a;}', '[[2]]', '', true], 'arrayKey' => ['<?php function target(){$a=[];try{$a[[]]=2;}catch(TypeError $e){return $a;}return 999;}', '[[]]', '', false], 'nullInvalidKey' => ['<?php function target(){$a=null;try{$a[[]]=2;}catch(TypeError $e){return $a;}return 999;}', '[[]]', '', false], 'nestedInvalidKey' => ['<?php function target(){$a=[];try{$a["x"][[]]=2;}catch(TypeError $e){return $a;}return 999;}', '[{"x":[]}]', '', false], 'nullInvalidRead' => ['<?php function target(){$a=null;try{return $a[[]];}catch(TypeError $e){return "error";}}', '[null]', '', true], 'arrayInvalidRead' => ['<?php function target(){$a=[];try{return $a[[]];}catch(TypeError $e){return "error";}}', '["error"]', '', false], 'nullInvalidIsset' => ['<?php function target(){$a=null;try{return isset($a[[]]);}catch(TypeError $e){return "error";}}', '[false]', '', false], 'arrayInvalidIsset' => ['<?php function target(){$a=[];try{return isset($a[[]]);}catch(TypeError $e){return "error";}}', '["error"]', '', false], 'intRead' => ['<?php function target(){$a=4;return $a[0];}', '[null]', '', true], 'stringRead' => ['<?php function target(){$a="abc";return [$a[0],$a[-1],$a["1"]];}', '[["a","c","b"]]', '', false], 'stringWrite' => ['<?php function target(){$a="abc";$r=($a[1]="xy");return [$r,$a];}', '[["x","axc"]]', '', true], 'stringNegativeWrite' => ['<?php function target(){$a="abc";$a[-1]="X";return $a;}', '["abX"]', '', false], 'stringPad' => ['<?php function target(){$a="a";$a[3]="Z";return $a;}', '["a  Z"]', '', false], 'stringInvalidKey' => ['<?php function target(){$a="abc";try{$a["x"]="Z";}catch(TypeError $e){return $a;}return 999;}', '["abc"]', '', false], 'stringAppend' => ['<?php function target(){$a="abc";try{$a[]="Z";}catch(Error $e){return $a;}return 999;}', '["abc"]', '', false], 'stringEmptyWrite' => ['<?php function target(){$a="abc";try{$a[1]="";}catch(Error $e){return $a;}return 999;}', '["abc"]', '', false], 'stringArrayWrite' => ['<?php function target(){$a="abc";try{$a[1]=[];}catch(TypeError $e){return $a;}return $a;}', '["aAc"]', '', true], 'appendMax' => ['<?php function target(){$a=[9223372036854775807=>1];try{$a[]=2;}catch(Error $e){return $a;}return 999;}', '[{"9223372036854775807":1}]', '', false], 'appendMaxAfterUnset' => ['<?php function target(){$a=[9223372036854775807=>1];unset($a[9223372036854775807]);$a[]=2;return $a;}', '[{"9223372036854775807":2}]', '', false], 'string-"1.0"-read' => ['<?php function target(){$s="abc";return $s["1.0"];}', '[]', 'TypeError', false], 'string-"1.0"-isset' => ['<?php function target(){$s="abc";return isset($s["1.0"]);}', '[false]', '', false], 'string-"1.0"-write' => ['<?php function target(){$s="abc";$r=($s["1.0"]="X");return [$r,$s];}', '[]', 'TypeError', false], 'string-"1x"-read' => ['<?php function target(){$s="abc";return $s["1x"];}', '["b"]', '', true], 'string-"1x"-isset' => ['<?php function target(){$s="abc";return isset($s["1x"]);}', '[false]', '', false], 'string-"1x"-write' => ['<?php function target(){$s="abc";$r=($s["1x"]="X");return [$r,$s];}', '[["X","aXc"]]', '', true], 'string-" 1 "-read' => ['<?php function target(){$s="abc";return $s[" 1 "];}', '["b"]', '', false], 'string-" 1 "-isset' => ['<?php function target(){$s="abc";return isset($s[" 1 "]);}', '[true]', '', false], 'string-" 1 "-write' => ['<?php function target(){$s="abc";$r=($s[" 1 "]="X");return [$r,$s];}', '[["X","aXc"]]', '', false], 'string-"+1"-read' => ['<?php function target(){$s="abc";return $s["+1"];}', '["b"]', '', false], 'string-"+1"-isset' => ['<?php function target(){$s="abc";return isset($s["+1"]);}', '[true]', '', false], 'string-"+1"-write' => ['<?php function target(){$s="abc";$r=($s["+1"]="X");return [$r,$s];}', '[["X","aXc"]]', '', false], 'string-"01"-read' => ['<?php function target(){$s="abc";return $s["01"];}', '["b"]', '', false], 'string-"01"-isset' => ['<?php function target(){$s="abc";return isset($s["01"]);}', '[true]', '', false], 'string-"01"-write' => ['<?php function target(){$s="abc";$r=($s["01"]="X");return [$r,$s];}', '[["X","aXc"]]', '', false], 'string-1.5-read' => ['<?php function target(){$s="abc";return $s[1.5];}', '["b"]', '', true], 'string-1.5-isset' => ['<?php function target(){$s="abc";return isset($s[1.5]);}', '[true]', '', true], 'string-1.5-write' => ['<?php function target(){$s="abc";$r=($s[1.5]="X");return [$r,$s];}', '[["X","aXc"]]', '', true], 'string-true-read' => ['<?php function target(){$s="abc";return $s[true];}', '["b"]', '', true], 'string-true-isset' => ['<?php function target(){$s="abc";return isset($s[true]);}', '[true]', '', false], 'string-true-write' => ['<?php function target(){$s="abc";$r=($s[true]="X");return [$r,$s];}', '[["X","aXc"]]', '', true], 'string-null-read' => ['<?php function target(){$s="abc";return $s[null];}', '["a"]', '', true], 'string-null-isset' => ['<?php function target(){$s="abc";return isset($s[null]);}', '[true]', '', false], 'string-null-write' => ['<?php function target(){$s="abc";$r=($s[null]="X");return [$r,$s];}', '[["X","Xbc"]]', '', true], 'string-[]-read' => ['<?php function target(){$s="abc";return $s[[]];}', '[]', 'TypeError', false], 'string-[]-isset' => ['<?php function target(){$s="abc";return isset($s[[]]);}', '[false]', '', false], 'string-[]-write' => ['<?php function target(){$s="abc";$r=($s[[]]="X");return [$r,$s];}', '[]', 'TypeError', false], 'string-"9223372036854775807"-read' => ['<?php function target(){$s="abc";return $s["9223372036854775807"];}', '[""]', '', true], 'string-"9223372036854775807"-isset' => ['<?php function target(){$s="abc";return isset($s["9223372036854775807"]);}', '[false]', '', false], 'string-"9223372036854775808"-read' => ['<?php function target(){$s="abc";return $s["9223372036854775808"];}', '[]', 'TypeError', false], 'string-"9223372036854775808"-isset' => ['<?php function target(){$s="abc";return isset($s["9223372036854775808"]);}', '[false]', '', false], 'string-bounds--5' => ['<?php function target(){$s="abc";$r=($s[-5]="X");return [$r,$s];}', '[[null,"abc"]]', '', true], 'string-bounds--4' => ['<?php function target(){$s="abc";$r=($s[-4]="X");return [$r,$s];}', '[[null,"abc"]]', '', true], 'string-bounds--3' => ['<?php function target(){$s="abc";$r=($s[-3]="X");return [$r,$s];}', '[["X","Xbc"]]', '', false], 'string-bounds-3' => ['<?php function target(){$s="abc";$r=($s[3]="X");return [$r,$s];}', '[["X","abcX"]]', '', false], 'string-bounds-4' => ['<?php function target(){$s="abc";$r=($s[4]="X");return [$r,$s];}', '[["X","abc X"]]', '', false], 'literalString' => ['<?php function target(){return "abc"[1];}', '["b"]', '', false], 'literalArrayInvalid' => ['<?php function target(){return [1][[]];}', '[]', 'TypeError', false], 'literalScalar' => ['<?php function target(){return (4)[0];}', '[null]', '', true], 'nestedStringRead' => ['<?php function target(){$a=["abc"];return $a[0][-1][0];}', '["c"]', '', false], 'nestedStringWrite' => ['<?php function target(){$a=["abc"];$a[0][-1]="X";return $a;}', '[["abX"]]', '', false], 'privateArray' => ['<?php class B{private array $x=[];}function target(){$b=new B;try{$b->x[0]=1;}catch(Error $e){return "private";}return 999;}', '["private"]', '', false], 'privateArrayIsset' => ['<?php class B{private array $x=[1];}function target(){$b=new B;return isset($b->x[0]);}', '[false]', '', false], 'typedArrayCreate' => ['<?php class B{public array $x;}function target(){$b=new B;$b->x[0]=1;return $b->x;}', '[[1]]', '', false], 'typedNullableInt' => ['<?php class B{public ?int $x;}function target(){$b=new B;try{$b->x[0]=1;}catch(TypeError $e){return isset($b->x);}return 999;}', '[false]', '', false], 'typedNullableIntNull' => ['<?php class B{public ?int $x=null;}function target(){$b=new B;try{$b->x[0]=1;}catch(TypeError $e){return $b->x;}return 999;}', '[null]', '', false], 'staticArray' => ['<?php class B{public static array $x=[1];}function target(){B::$x[]=2;return B::$x;}', '[[1,2]]', '', false], 'readonlyArray' => ['<?php class B{public readonly array $x;function __construct(){$this->x=[1];}}function target(){$b=new B;try{$b->x[0]=2;}catch(Error $e){return $b->x;}return 999;}', '[[1]]', '', false], 'arrayReference' => ['<?php function target(){$a=[];$r=&$a["x"];$r=2;return $a;}', '[{"x":2}]', '', false], 'arrayReferenceInitial' => ['<?php function target(){$a=[];$r=&$a["x"];return [$a,$r];}', '[[{"x":null},null]]', '', false], 'arrayAliasDestination' => ['<?php function target(){$a=null;$b=2;$a["x"]=&$b;$b=3;return $a;}', '[{"x":3}]', '', false], 'stringReference' => ['<?php function target(){$a="abc";try{$r=&$a[0];}catch(Error $e){return $a;}return 999;}', '["abc"]', '', false], 'stringUnset' => ['<?php function target(){$a="abc";try{unset($a[0]);}catch(Error $e){return $a;}return 999;}', '["abc"]', '', false], 'scalarUnset' => ['<?php function target(){$a=4;unset($a[0]);return $a;}', '[]', 'Error', false], 'stringIncrement' => ['<?php function target(){$a="abc";try{$a[0]++;}catch(Error $e){return $a;}return 999;}', '["abc"]', '', false], 'arrayMissingIncrement' => ['<?php function target(){$a=[];$a[0]++;return $a;}', '[[1]]', '', true], 'plainObject' => ['<?php function target(){$a=new stdClass;try{$a[0]=1;}catch(Error $e){return "object";}return 999;}', '["object"]', '', false], 'arrayFractionalKey' => ['<?php function target(){$a=[];$a[1.5]=2;return $a;}', '[{"1":2}]', '', true], 'arrayaccess:read-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=$b["n"];return [$r,$b->items,$b->log];}', '[[2,{"x":[1],"n":2},["get:n"]]]', '', false], 'arrayaccess:write-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=($b["n"]=3);return [$r,$b->items,$b->log];}', '[[3,{"x":[1],"n":3},["set:n"]]]', '', false], 'arrayaccess:isset-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=isset($b["n"]);return [$r,$b->items,$b->log];}', '[[true,{"x":[1],"n":2},["exists:n"]]]', '', false], 'arrayaccess:coalesce-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=$b["n"]??9;return [$r,$b->items,$b->log];}', '[[2,{"x":[1],"n":2},["exists:n","get:n"]]]', '', false], 'arrayaccess:empty-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=empty($b["n"]);return [$r,$b->items,$b->log];}', '[[false,{"x":[1],"n":2},["exists:n","get:n"]]]', '', false], 'arrayaccess:unset-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;unset($b["n"]);$r=1;return [$r,$b->items,$b->log];}', '[[1,{"x":[1]},["unset:n"]]]', '', false], 'arrayaccess:increment-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=$b["n"]++;return [$r,$b->items,$b->log];}', '[[2,{"x":[1],"n":2},["get:n"]]]', '', true], 'arrayaccess:compound-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=($b["n"]+=3);return [$r,$b->items,$b->log];}', '[[5,{"x":[1],"n":5},["get:n","set:n"]]]', '', false], 'arrayaccess:nestedwrite-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$b["x"][0]=3;$r=1;return [$r,$b->items,$b->log];}', '[[1,{"x":[1],"n":2},["get:x"]]]', '', true], 'arrayaccess:nestedread-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=$b["x"][0];return [$r,$b->items,$b->log];}', '[[1,{"x":[1],"n":2},["get:x"]]]', '', false], 'arrayaccess:nestedisset-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=isset($b["x"][0]);return [$r,$b->items,$b->log];}', '[[true,{"x":[1],"n":2},["exists:x","get:x"]]]', '', false], 'arrayaccess:reference-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=&$b["n"];$r=9;return [$r,$b->items,$b->log];}', '[[9,{"x":[1],"n":2},["get:n"]]]', '', true], 'arrayaccess:alias-value' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=9;$b["n"]=&$r;return [$r,$b->items,$b->log];}', '[]', 'Error', true], 'arrayaccess:read-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=$b["n"];return [$r,$b->items,$b->log];}', '[[2,{"x":[1],"n":2},["get:n"]]]', '', false], 'arrayaccess:write-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=($b["n"]=3);return [$r,$b->items,$b->log];}', '[[3,{"x":[1],"n":3},["set:n"]]]', '', false], 'arrayaccess:isset-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=isset($b["n"]);return [$r,$b->items,$b->log];}', '[[true,{"x":[1],"n":2},["exists:n"]]]', '', false], 'arrayaccess:coalesce-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=$b["n"]??9;return [$r,$b->items,$b->log];}', '[[2,{"x":[1],"n":2},["exists:n","get:n"]]]', '', false], 'arrayaccess:empty-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=empty($b["n"]);return [$r,$b->items,$b->log];}', '[[false,{"x":[1],"n":2},["exists:n","get:n"]]]', '', false], 'arrayaccess:unset-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;unset($b["n"]);$r=1;return [$r,$b->items,$b->log];}', '[[1,{"x":[1]},["unset:n"]]]', '', false], 'arrayaccess:increment-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=$b["n"]++;return [$r,$b->items,$b->log];}', '[[2,{"x":[1],"n":3},["get:n"]]]', '', false], 'arrayaccess:compound-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=($b["n"]+=3);return [$r,$b->items,$b->log];}', '[[5,{"x":[1],"n":5},["get:n","set:n"]]]', '', false], 'arrayaccess:nestedwrite-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$b["x"][0]=3;$r=1;return [$r,$b->items,$b->log];}', '[[1,{"x":[3],"n":2},["get:x"]]]', '', false], 'arrayaccess:nestedread-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=$b["x"][0];return [$r,$b->items,$b->log];}', '[[1,{"x":[1],"n":2},["get:x"]]]', '', false], 'arrayaccess:nestedisset-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=isset($b["x"][0]);return [$r,$b->items,$b->log];}', '[[true,{"x":[1],"n":2},["exists:x","get:x"]]]', '', false], 'arrayaccess:reference-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=&$b["n"];$r=9;return [$r,$b->items,$b->log];}', '[[9,{"x":[1],"n":9},["get:n"]]]', '', false], 'arrayaccess:alias-ref' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function &offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function target(){$b=new Box;$r=9;$b["n"]=&$r;return [$r,$b->items,$b->log];}', '[]', 'Error', false], 'arrayaccess:unset-null' => ['<?php function target(){$a=null;unset($a[0]);return $a;}', '[null]', '', false], 'arrayaccess:unset-false' => ['<?php function target(){$a=false;unset($a[0]);return $a;}', '[false]', '', true], 'arrayaccess:unset-true' => ['<?php function target(){$a=true;unset($a[0]);return $a;}', '[]', 'Error', false], 'arrayaccess:unset-4' => ['<?php function target(){$a=4;unset($a[0]);return $a;}', '[]', 'Error', false], 'arrayaccess:unset-4.5' => ['<?php function target(){$a=4.5;unset($a[0]);return $a;}', '[]', 'Error', false], 'arrayaccess:readonly-object' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}class Holder{public readonly Box $box;function __construct(){$this->box=new Box;}}function target(){$h=new Holder;$h->box["n"]=8;return [$h->box->items,$h->box->log];}', '[[{"x":[1],"n":8},["set:n"]]]', '', false], 'arrayaccess:computed-object' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function make(){return new Box;}function target(){return make()["n"];}', '[2]', '', false], 'arrayaccess:computed-coalesce' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}function make(){return new Box;}function target(){return make()["absent"]??9;}', '[9]', '', false], 'arrayaccess:literal-coalesce' => ['<?php function target(){return []["absent"]??9;}', '[9]', '', false], 'arrayaccess:literal-empty' => ['<?php function target(){return empty([]["absent"]);}', '[true]', '', false], 'arrayaccess:literal-nested-coalesce' => ['<?php function target(){return []["absent"]["nested"]??9;}', '[9]', '', false], 'compound:local-order' => ['<?php function target(){$a=1;$a+=($a=2);return $a;}', '[4]', '', false], 'compound:array-order' => ['<?php function target(){$a=[1];$a[0]+=($a[0]=2);return $a;}', '[[4]]', '', false], 'compound:string-compound' => ['<?php function target(){$a="abc";try{$a[0].="x";}catch(Throwable $e){return get_class($e);}return $a;}', '["Error"]', '', false], 'compound:string-numeric' => ['<?php function target(){$a="123";try{$a[0]+=2;}catch(Throwable $e){return get_class($e);}return $a;}', '["Error"]', '', false], 'compound:string-rhs' => ['<?php function target(){$a="abc";$b=0;try{$a[0]+=++$b;}catch(Throwable $e){return [$b,get_class($e)];}return $a;}', '[[1,"Error"]]', '', false], 'compound:null-failed' => ['<?php function target(){$a=null;try{$a[0]+=new stdClass;}catch(Throwable $e){return [$a,get_class($e)];}return $a;}', '[[[null],"TypeError"]]', '', true], 'compound:array-failed' => ['<?php function target(){$a=[];try{$a[0]+=new stdClass;}catch(Throwable $e){return [$a,get_class($e)];}return $a;}', '[[[null],"TypeError"]]', '', true], 'compound:string-invalid-key' => ['<?php function target(){$a="123";try{$a[[]]+=2;}catch(Throwable $e){return get_class($e);}return $a;}', '["TypeError"]', '', false], 'compound:key-1.2x' => ['<?php function target(){$s="abc";return $s[\'1.2x\'];}', '[]', 'TypeError', false], 'compound:key-1e2x' => ['<?php function target(){$s="abc";return $s[\'1e2x\'];}', '[]', 'TypeError', false], 'compound:key-1e' => ['<?php function target(){$s="abc";return $s[\'1e\'];}', '["b"]', '', true], 'compound:key-1.x' => ['<?php function target(){$s="abc";return $s[\'1.x\'];}', '[]', 'TypeError', false], 'compound:key-  +001x' => ['<?php function target(){$s="abc";return $s[\'  +001x\'];}', '["b"]', '', true], 'compound:key-9223372036854775807x' => ['<?php function target(){$s="abc";return $s[\'9223372036854775807x\'];}', '[""]', '', true], 'compound:caught-inspection' => ['<?php function target(){try{1/0;}catch(DivisionByZeroError $e){$same=$e;return [get_class($e),$same===$e,$e->getCode(),$e->getPrevious(),$e instanceof Error];}return 999;}', '[["DivisionByZeroError",true,0,null,true]]', '', false], 'compound:caught-rethrow' => ['<?php function target(){try{try{1/0;}catch(DivisionByZeroError $e){throw $e;}}catch(Error $other){return get_class($other);}return 999;}', '["DivisionByZeroError"]', '', false], 'rejected:reference:[]' => ['<?php function target(){$s="abc";$r=&$s[[]];return $s;}', '[]', 'TypeError', false], 'rejected:increment:[]' => ['<?php function target(){$s="abc";$s[[]]++;return $s;}', '[]', 'TypeError', false], 'rejected:unset:[]' => ['<?php function target(){$s="abc";unset($s[[]]);return $s;}', '[]', 'Error', false], 'rejected:nested:[]' => ['<?php function target(){$s="abc";$s[[]][0]="X";return $s;}', '[]', 'TypeError', false], 'rejected:compound:[]' => ['<?php function target(){$s="abc";$s[[]].="X";return $s;}', '[]', 'TypeError', false], 'rejected:reference:"1x"' => ['<?php function target(){$s="abc";$r=&$s["1x"];return $s;}', '[]', 'Error', true], 'rejected:increment:"1x"' => ['<?php function target(){$s="abc";$s["1x"]++;return $s;}', '[]', 'Error', true], 'rejected:unset:"1x"' => ['<?php function target(){$s="abc";unset($s["1x"]);return $s;}', '[]', 'Error', false], 'rejected:nested:"1x"' => ['<?php function target(){$s="abc";$s["1x"][0]="X";return $s;}', '[]', 'Error', true], 'rejected:compound:"1x"' => ['<?php function target(){$s="abc";$s["1x"].="X";return $s;}', '[]', 'Error', true], 'rejected:reference:1.5' => ['<?php function target(){$s="abc";$r=&$s[1.5];return $s;}', '[]', 'Error', true], 'rejected:increment:1.5' => ['<?php function target(){$s="abc";$s[1.5]++;return $s;}', '[]', 'Error', true], 'rejected:unset:1.5' => ['<?php function target(){$s="abc";unset($s[1.5]);return $s;}', '[]', 'Error', false], 'rejected:nested:1.5' => ['<?php function target(){$s="abc";$s[1.5][0]="X";return $s;}', '[]', 'Error', true], 'rejected:compound:1.5' => ['<?php function target(){$s="abc";$s[1.5].="X";return $s;}', '[]', 'Error', true], 'rejected:readonly-array-object' => ['<?php class Box implements ArrayAccess {public array $items=["x"=>[1],"n"=>2];public array $log=[];public function offsetExists(mixed $key):bool{$this->log[]="exists:".$key;return isset($this->items[$key]);}public function offsetGet(mixed $key):mixed{$this->log[]="get:".$key;return $this->items[$key];}public function offsetSet(mixed $key,mixed $value):void{$this->log[]="set:".$key;$this->items[$key]=$value;}public function offsetUnset(mixed $key):void{$this->log[]="unset:".$key;unset($this->items[$key]);}}class Holder{public readonly array $boxes;function __construct(){$this->boxes=[new Box];}}function target(){$h=new Holder;$h->boxes[0]["n"]=8;return [$h->boxes[0]->items,$h->boxes[0]->log];}', '[]', 'Error', false], 'caught:fresh-identities' => ['<?php function caught(){try{1/0;}catch(Error $e){return $e;}}function target(){$objects=[];for($i=0;$i<2;$i++){$objects[]=caught();}return $objects[0]===$objects[1];}', '[false]', '', false]] as $name => $case) {
570            if (str_contains($case[0], 'ArrayAccess')) {
571                yield $name => $case;
572            }
573        }
574    }
575}
576