Retrieves a sensitive value wrapped by the PHP #[SensitiveParameter] mechanism.
The examples focus on the operation itself, including the important distinction: SensitiveParameterValue::__debugInfo redacts debug output; getValue deliberately reveals the wrapped value.
What It Does
Use the examples below to observe the behavior on a small dataset before extending it to application code.
Syntax and Return Value
SensitiveParameterValue::getValue(): mixed
The displayed signature describes the API or identifies any correction or optional dependency. When a parameter is optional, supply it only when the task requires it.
Declared return type: mixed. Read the behavior notes for important cases such as empty collections and destructive iteration.
Example 1: Basic Use
getValue deliberately unwraps sensitive data. Only forward it to trusted operations; never echo or log the secret itself.
<?php
$secret = new SensitiveParameterValue('token-abc');
$trustedFunction = static fn(string $token): int => strlen($token);
$length = $trustedFunction($secret->getValue());
echo "validated secret length: " . $length;
Output from a successful local PHP 8.4 run:
validated secret length: 9
Example 2: Checking Behavior
getValue deliberately unwraps sensitive data. Only forward it to trusted operations; never echo or log the secret itself.
<?php
$secret = new SensitiveParameterValue('key-123');
$trustedFunction = static fn(string $token): int => strlen($token);
$length = $trustedFunction($secret->getValue());
echo "validated secret length: " . $length;
Output from a successful local PHP 8.4 run:
validated secret length: 7
Example 3: Practical Example
getValue deliberately unwraps sensitive data. Only forward it to trusted operations; never echo or log the secret itself.
<?php
$secret = new SensitiveParameterValue('private-value');
$trustedFunction = static fn(string $token): int => strlen($token);
$length = $trustedFunction($secret->getValue());
echo "validated secret length: " . $length;
Output from a successful local PHP 8.4 run:
validated secret length: 13
Important Behavior and Edge Cases
Revealing the value defeats the protection if it is logged; return it only to trusted application code.
Comparison with Related Approaches
| Approach | Difference |
|---|---|
| SensitiveParameterValue::getValue | Retrieves a sensitive value wrapped by the PHP #[SensitiveParameter] mechanism. |
| Related API or alternative | SensitiveParameterValue::__debugInfo redacts debug output; getValue deliberately reveals the wrapped value. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Ignoring the operation-specific limits | Revealing the value defeats the protection if it is logged; return it only to trusted application code. |
| Confusing it with a related API | SensitiveParameterValue::__debugInfo redacts debug output; getValue deliberately reveals the wrapped value. |
Key Takeaways
- Retrieves a sensitive value wrapped by the PHP #[SensitiveParameter] mechanism.
- Revealing the value defeats the protection if it is logged; return it only to trusted application code.
- SensitiveParameterValue::__debugInfo redacts debug output; getValue deliberately reveals the wrapped value.
Use SensitiveParameterValue::getValue when its documented behavior matches the problem. Test the relevant edge cases in your own runtime before deploying it.