|
| 1 | +--TEST-- |
| 2 | +The SensitiveParameterValue replacement value correctly captures the original value. |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | + |
| 6 | +function test( |
| 7 | + $foo, |
| 8 | + #[SensitiveParameter] $bar, |
| 9 | + $baz |
| 10 | +) { |
| 11 | + throw new Exception('Error'); |
| 12 | +} |
| 13 | + |
| 14 | +try { |
| 15 | + test('foo', 'bar', 'baz'); |
| 16 | + echo 'Not reached'; |
| 17 | +} catch (Exception $e) { |
| 18 | + echo $e->getMessage(), PHP_EOL; |
| 19 | + $testFrame = $e->getTrace()[0]; |
| 20 | + var_dump($testFrame['function']); |
| 21 | + var_dump(count($testFrame['args'])); |
| 22 | + var_dump($testFrame['args'][0]); |
| 23 | + assert($testFrame['args'][1] instanceof SensitiveParameterValue); |
| 24 | + var_dump($testFrame['args'][1]->getValue()); |
| 25 | + var_dump($testFrame['args'][2]); |
| 26 | + echo "Success", PHP_EOL; |
| 27 | +} |
| 28 | + |
| 29 | +function test2( |
| 30 | + $foo, |
| 31 | + #[SensitiveParameter] ...$variadic, |
| 32 | +) { |
| 33 | + throw new Exception('Error 2'); |
| 34 | +} |
| 35 | + |
| 36 | +try { |
| 37 | + test2('foo', 'variadic1', 'variadic2', 'variadic3'); |
| 38 | + echo 'Not reached'; |
| 39 | +} catch (Exception $e) { |
| 40 | + echo $e->getMessage(), PHP_EOL; |
| 41 | + $testFrame = $e->getTrace()[0]; |
| 42 | + var_dump($testFrame['function']); |
| 43 | + var_dump(count($testFrame['args'])); |
| 44 | + var_dump($testFrame['args'][0]); |
| 45 | + assert($testFrame['args'][1] instanceof SensitiveParameterValue); |
| 46 | + var_dump($testFrame['args'][1]->getValue()); |
| 47 | + assert($testFrame['args'][2] instanceof SensitiveParameterValue); |
| 48 | + var_dump($testFrame['args'][2]->getValue()); |
| 49 | + assert($testFrame['args'][3] instanceof SensitiveParameterValue); |
| 50 | + var_dump($testFrame['args'][3]->getValue()); |
| 51 | + echo "Success", PHP_EOL; |
| 52 | +} |
| 53 | + |
| 54 | +?> |
| 55 | +--EXPECTF-- |
| 56 | +Error |
| 57 | +string(4) "test" |
| 58 | +int(3) |
| 59 | +string(3) "foo" |
| 60 | +string(3) "bar" |
| 61 | +string(3) "baz" |
| 62 | +Success |
| 63 | +Error 2 |
| 64 | +string(5) "test2" |
| 65 | +int(4) |
| 66 | +string(3) "foo" |
| 67 | +string(9) "variadic1" |
| 68 | +string(9) "variadic2" |
| 69 | +string(9) "variadic3" |
| 70 | +Success |
0 commit comments