Skip to content

Fix undefined array key "desc" in element property lexicon translation - #16988

Open
Ibochkarev wants to merge 4 commits into
modxcms:3.xfrom
Ibochkarev:fix/undefined-desc-modElement
Open

Fix undefined array key "desc" in element property lexicon translation#16988
Ibochkarev wants to merge 4 commits into
modxcms:3.xfrom
Ibochkarev:fix/undefined-desc-modElement

Conversation

@Ibochkarev

@Ibochkarev Ibochkarev commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What changed and why

modElement::get('properties') and modPropertySet::get('properties') read $property['desc'] without checking the key. PHP 8 logs Undefined 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

php -l core/src/Revolution/modElement.php
php -l core/src/Revolution/modPropertySet.php
XDEBUG_MODE=coverage core/vendor/bin/phpunit --filter testGetPropertiesWithoutDescKey -c ./_build/test/phpunit.xml

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 at modElement.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 desc is present, behavior is unchanged. When both desc and description are missing, desc_trans is an empty string instead of a warning.

Breaking change assessment

No API or signature changes. Safe for patch releases.

Test coverage

testGetPropertiesWithoutDescKey with two data-provider cases: missing desc (no warnings, empty desc_trans) and description fallback only.

Contributors

N/A

AI tool use

Cursor agent wrote the patch, regression test, and review notes.

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 Ibochkarev added the bug The issue in the code or project, which should be addressed. label Aug 12, 2026
@smg6511

smg6511 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

@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.

@Ibochkarev

Copy link
Copy Markdown
Collaborator Author

@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.

@mkschell

Copy link
Copy Markdown
Member

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.

@smg6511 smg6511 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is a nit, but 'description' is not an expected key on the properties array; it's only used in defining a non-default prop set object and isn't accessed here.

Comment thread core/src/Revolution/modElement.php Outdated
Comment thread core/src/Revolution/modPropertySet.php Outdated
Ibochkarev and others added 2 commits August 13, 2026 21:25
Co-authored-by: Jim Graham <jim@pixelsandstrings.com>
Co-authored-by: Jim Graham <jim@pixelsandstrings.com>
@Ibochkarev
Ibochkarev requested a review from smg6511 August 13, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug The issue in the code or project, which should be addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants