Incomplete statement about the Null Coalescing Operator
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
From manual page: https://php.net/language.operators.comparison
In the Null Coalescing Operator section, the documentation states "The expression (expr1) ?? (expr2) evaluates to expr2 if expr1 is null, and expr1 otherwise." which is not fully correct. The next sentence states it suppresses notices and warning for non existent expr1, just like isset. The code block above has an "identical" example given of an array access situation with ?? and with if/else block using isset. This led me to believe that I could substitute that array access for any expression and it would still be identical. This is not the case. This next code block appears to be a proper equivalence example.
<?php
// Example usage for: Null Coalesce Operator
$result = _expr_ ?? 'default';
// The above is identical to this if/else statement
if (isset(_expr_)) {
$tmp_var = _expr_;
if ($tmp_var !== null) {
$result = $tmp_var;
}
else {
$result = 'default';
}
} else {
$result = 'default';
}
?>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the linked PHP manual page and review the Null Coalescing Operator section, especially the statement about expr1 and the adjacent equivalence examples. Update the wording or example so the documented equivalence accurately reflects the operator's behavior for the shown expression, then verify the rendered documentation is clear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100