Fix undefined array key "desc" in element property lexicon translation - #16988
Fix undefined array key "desc" in element property lexicon translation#16988Ibochkarev wants to merge 4 commits into
Conversation
Guard property description lookup in modElement::get() and modPropertySet::get() when the desc key is missing, preventing PHP 8 warnings in the manager log.
|
@Ibochkarev @Mark-H - Guys, just one little thing re the unit test: I don't think it's needed or really appropriate to basically be checking the correctness of how something is coded (in this case that there's a null guard to avoid php errors/warnings) via a UT (at least not one that's to be included in the code base's suite). IMO, that part of this PR can be dropped. |
Hi! I've removed the changes from the test. |
|
For me, that was a bit of a grey area. The test wasn't directly testing the input/output contract of the method, but I saw it as testing for an unwanted side effect (as opposed to testing the correctness of the code). I see it's been modified and approved, and that's ok with me. IMO we should be working to reduce side effects of functions (can you tell I'm into FP?) but I'm also ok with not explicitly testing for them (or their absence) if that's the general sentiment. |
Co-authored-by: Jim Graham <jim@pixelsandstrings.com>
Co-authored-by: Jim Graham <jim@pixelsandstrings.com>
What changed and why
modElement::get('properties')andmodPropertySet::get('properties')read$property['desc']without checking the key. PHP 8 logsUndefined array key "desc"when a property definition has no description field.The fix resolves the label with
$property['desc'] ?? $property['description'] ?? ''and calls the lexicon only when the result is non-empty. Both classes share the same translation loop, so both get the same guard.How to test
Exit 0 on PHP 8.4 locally.
To see the original warning: open an element in the manager whose stored properties omit
desc(imported or legacy definitions). Before this change, the log pointed atmodElement.php:165.Related issue(s)/PR(s)
Found in the manager error log. Part of the broader PHP 8 cleanup tracked in #16018.
Compatibility notes
Applies on PHP 8+. When
descis present, behavior is unchanged. When bothdescanddescriptionare missing,desc_transis an empty string instead of a warning.Breaking change assessment
No API or signature changes. Safe for patch releases.
Test coverage
testGetPropertiesWithoutDescKeywith two data-provider cases: missingdesc(no warnings, emptydesc_trans) anddescriptionfallback only.Contributors
N/A
AI tool use
Cursor agent wrote the patch, regression test, and review notes.