Skip to content

Improve select field value handling and null checks#144

Merged
shannah merged 1 commit intomasterfrom
claude/fix-count-type-error-JOacT
Apr 29, 2026
Merged

Improve select field value handling and null checks#144
shannah merged 1 commit intomasterfrom
claude/fix-count-type-error-JOacT

Conversation

@shannah
Copy link
Copy Markdown
Owner

@shannah shannah commented Apr 29, 2026

Summary

Refactored the value handling logic in the select form tool to improve robustness and clarity when processing field values, particularly for array and null cases.

Key Changes

  • Array handling: Changed from @count($val)>0 to explicit is_array($val) check for better type safety and removed error suppression operator
  • Ternary operator: Simplified array value return to use ternary operator: count($val) > 0 ? $val[0] : null
  • Non-array handling: Added explicit null and empty string checks for scalar values, returning null only when appropriate instead of always returning null
  • Code cleanup: Removed unnecessary blank lines for more compact code

Implementation Details

The changes improve the distinction between three cases:

  1. Array values: Returns first element if array is non-empty, otherwise null
  2. Null/empty string values: Returns null
  3. Other scalar values: Returns the value as-is

This prevents unintended null returns for valid scalar values while maintaining backward compatibility for array and null cases.

https://claude.ai/code/session_01RCVV3MQ8NYE21NfbQVvHzn

PHP 8 made count() throw TypeError on non-Countable arguments, which the
@ suppression operator no longer hides. Dataface_FormTool_select::pushValue
was calling @count() on $element->getValue(), which can be a string when
the element is an HTML_QuickForm_hidden (e.g. via ShortRelatedRecordForm).

Branch on is_array() before counting, and return the scalar value as-is
otherwise (treating null/empty string as null to preserve the previous
"no value" semantics).

Fixes #143

https://claude.ai/code/session_01RCVV3MQ8NYE21NfbQVvHzn
@shannah
Copy link
Copy Markdown
Owner Author

shannah commented Apr 29, 2026

Fixes #143

@shannah shannah merged commit 0cd9cfd into master Apr 29, 2026
12 checks passed
@shannah shannah deleted the claude/fix-count-type-error-JOacT branch April 29, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants