|
| 1 | +--TEST-- |
| 2 | +GH-23628 001: Tracing JIT reads undefined property slots of a lazy proxy |
| 3 | +--INI-- |
| 4 | +opcache.enable=1 |
| 5 | +opcache.enable_cli=1 |
| 6 | +opcache.file_update_protection=0 |
| 7 | +opcache.jit=tracing |
| 8 | +opcache.jit_buffer_size=32M |
| 9 | +opcache.jit_hot_loop=16 |
| 10 | +--EXTENSIONS-- |
| 11 | +opcache |
| 12 | +--FILE-- |
| 13 | +<?php |
| 14 | +final class Table { |
| 15 | + protected array $map = ['start' => ['next' => 1]]; |
| 16 | + public int $count = 0; |
| 17 | + public function parse(int $n): int { |
| 18 | + $ok = 0; |
| 19 | + for ($i = 0; $i < $n; $i++) { |
| 20 | + if (isset($this->map['start']['next'])) { |
| 21 | + $ok++; |
| 22 | + } else { |
| 23 | + throw new RuntimeException('isset false at ' . $i); |
| 24 | + } |
| 25 | + } |
| 26 | + return $ok; |
| 27 | + } |
| 28 | + public function coalesce(int $n): int { |
| 29 | + $sum = 0; |
| 30 | + for ($i = 0; $i < $n; $i++) { |
| 31 | + $sum += $this->map['start']['next'] ?? 100; |
| 32 | + } |
| 33 | + return $sum; |
| 34 | + } |
| 35 | + public function read(int $n): int { |
| 36 | + $sum = 0; |
| 37 | + for ($i = 0; $i < $n; $i++) { |
| 38 | + $sum += $this->map['start']['next']; |
| 39 | + } |
| 40 | + return $sum; |
| 41 | + } |
| 42 | + public function write(int $n): int { |
| 43 | + for ($i = 0; $i < $n; $i++) { |
| 44 | + $this->map['start']['next'] = $i; |
| 45 | + $this->count++; |
| 46 | + } |
| 47 | + return $this->map['start']['next']; |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +$reflector = new ReflectionClass(Table::class); |
| 52 | + |
| 53 | +$proxy = $reflector->newLazyProxy(fn () => new Table()); |
| 54 | +var_dump($proxy->parse(100)); |
| 55 | +$proxy = $reflector->newLazyProxy(fn () => new Table()); |
| 56 | +var_dump($proxy->coalesce(100)); |
| 57 | +$proxy = $reflector->newLazyProxy(fn () => new Table()); |
| 58 | +var_dump($proxy->read(100)); |
| 59 | +$proxy = $reflector->newLazyProxy(fn () => new Table()); |
| 60 | +var_dump($proxy->write(100)); |
| 61 | +var_dump($proxy->count); |
| 62 | + |
| 63 | +$ghost = $reflector->newLazyGhost(function (Table $table) {}); |
| 64 | +var_dump($ghost->parse(100)); |
| 65 | +?> |
| 66 | +--EXPECT-- |
| 67 | +int(100) |
| 68 | +int(100) |
| 69 | +int(100) |
| 70 | +int(99) |
| 71 | +int(100) |
| 72 | +int(100) |
0 commit comments