|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace ByRefWritebackNativeType; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertNativeType; |
| 6 | +use function PHPStan\Testing\assertType; |
| 7 | + |
| 8 | +function offsetCapture(string $s): void |
| 9 | +{ |
| 10 | + if (! preg_match('/(a)(b)?/', $s, $m, PREG_OFFSET_CAPTURE)) { |
| 11 | + return; |
| 12 | + } |
| 13 | + |
| 14 | + assertType("array{0: array{non-falsy-string, int<-1, max>}, 1: array{'a', int<-1, max>}, 2?: array{'b', int<-1, max>}}", $m); |
| 15 | + assertNativeType("array{0: array{non-falsy-string, int<-1, max>}, 1: array{'a', int<-1, max>}, 2?: array{'b', int<-1, max>}}", $m); |
| 16 | +} |
| 17 | + |
| 18 | +function noFlags(string $s): void |
| 19 | +{ |
| 20 | + if (! preg_match('/(a)(b)?/', $s, $m)) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + assertType("array{0: non-falsy-string, 1: 'a', 2?: 'b'}", $m); |
| 25 | + assertNativeType("array{0: non-falsy-string, 1: 'a', 2?: 'b'}", $m); |
| 26 | +} |
| 27 | + |
| 28 | +/** @param-out string $v */ |
| 29 | +function paramOutContradictsDeclaration(int &$v): void |
| 30 | +{ |
| 31 | + $v = 'now a string'; |
| 32 | +} |
| 33 | + |
| 34 | +function userlandParamOut(): void |
| 35 | +{ |
| 36 | + $x = 1; |
| 37 | + paramOutContradictsDeclaration($x); |
| 38 | + |
| 39 | + assertType('string', $x); |
| 40 | + assertNativeType('mixed', $x); |
| 41 | +} |
0 commit comments