|  | 
|  | 1 | +--TEST-- | 
|  | 2 | +Named Parameters are optimized for known constructors | 
|  | 3 | +--INI-- | 
|  | 4 | +opcache.enable=1 | 
|  | 5 | +opcache.enable_cli=1 | 
|  | 6 | +opcache.optimization_level=-1 | 
|  | 7 | +opcache.opt_debug_level=0x20000 | 
|  | 8 | +--SKIPIF-- | 
|  | 9 | +<?php | 
|  | 10 | +    if(substr(PHP_OS, 0, 3) == 'WIN') die("skip on windows: Internal classes cannot be optimized"); | 
|  | 11 | +?> | 
|  | 12 | +--EXTENSIONS-- | 
|  | 13 | +opcache | 
|  | 14 | +--FILE-- | 
|  | 15 | +<?php | 
|  | 16 | + | 
|  | 17 | +final class MyClass | 
|  | 18 | +{ | 
|  | 19 | +	private function __construct( | 
|  | 20 | +		private \Random\Engine $foo, | 
|  | 21 | +		private int $bar = 0, | 
|  | 22 | +	) {} | 
|  | 23 | + | 
|  | 24 | +	public static function new(int $bar): self | 
|  | 25 | +	{ | 
|  | 26 | +		$engine = new \Random\Engine\Xoshiro256StarStar(seed: 123); | 
|  | 27 | +		return new self(foo: $engine, bar: $bar); | 
|  | 28 | +	} | 
|  | 29 | +} | 
|  | 30 | + | 
|  | 31 | +MyClass::new(bar: 1); | 
|  | 32 | + | 
|  | 33 | +?> | 
|  | 34 | +--EXPECTF-- | 
|  | 35 | +$_main: | 
|  | 36 | +     ; (lines=4, args=0, vars=0, tmps=0) | 
|  | 37 | +     ; (after optimizer) | 
|  | 38 | +     ; %s | 
|  | 39 | +0000 INIT_STATIC_METHOD_CALL 1 string("MyClass") string("new") | 
|  | 40 | +0001 SEND_VAL int(1) 1 | 
|  | 41 | +0002 DO_UCALL | 
|  | 42 | +0003 RETURN int(1) | 
|  | 43 | + | 
|  | 44 | +MyClass::__construct: | 
|  | 45 | +     ; (lines=7, args=2, vars=2, tmps=0) | 
|  | 46 | +     ; (after optimizer) | 
|  | 47 | +     ; %s | 
|  | 48 | +0000 CV0($foo) = RECV 1 | 
|  | 49 | +0001 CV1($bar) = RECV_INIT 2 int(0) | 
|  | 50 | +0002 ASSIGN_OBJ THIS string("foo") | 
|  | 51 | +0003 OP_DATA CV0($foo) | 
|  | 52 | +0004 ASSIGN_OBJ THIS string("bar") | 
|  | 53 | +0005 OP_DATA CV1($bar) | 
|  | 54 | +0006 RETURN null | 
|  | 55 | + | 
|  | 56 | +MyClass::new: | 
|  | 57 | +     ; (lines=10, args=1, vars=2, tmps=1) | 
|  | 58 | +     ; (after optimizer) | 
|  | 59 | +     ; %s | 
|  | 60 | +0000 CV0($bar) = RECV 1 | 
|  | 61 | +0001 V2 = NEW 1 string("Random\\Engine\\Xoshiro256StarStar") | 
|  | 62 | +0002 SEND_VAL int(123) 1 | 
|  | 63 | +0003 DO_FCALL | 
|  | 64 | +0004 CV1($engine) = QM_ASSIGN V2 | 
|  | 65 | +0005 V2 = NEW 2 (self) (exception) | 
|  | 66 | +0006 SEND_VAR CV1($engine) 1 | 
|  | 67 | +0007 SEND_VAR CV0($bar) 2 | 
|  | 68 | +0008 DO_FCALL | 
|  | 69 | +0009 RETURN V2 | 
|  | 70 | +LIVE RANGES: | 
|  | 71 | +     2: 0002 - 0004 (new) | 
|  | 72 | +     2: 0006 - 0009 (new) | 
0 commit comments