Skip to content

[4.x] Treat null-valued event arguments as existing - #52

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-null-arguments
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-null-arguments

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

AbstractEvent::getArgument()/hasArgument() and Event::addArgument()/removeArgument() check arguments with isset(), so an argument whose value is null is treated as missing:

  • (new Event('x', ['a' => null]))->hasArgument('a') is false
  • getArgument('a', 'default') returns 'default' instead of null
  • addArgument('a', 'v') overwrites the null value it should keep
  • removeArgument('a') does not remove the key

The four methods now use array_key_exists(). Because offsetExists() delegates to hasArgument(), isset($event['a']) is now true for a null-valued argument as well (this differs from plain PHP arrays, but matches hasArgument()). Behaviour changes only for null-valued arguments.

Testing Instructions

AbstractEventTest::testNullValuedArgumentExists() and EventTest::testNullValuedArgumentIsKeptAndRemoved() cover all four methods. Both fail before the change in src/.

Run vendor/bin/phpunit.

Documentation Changes Required

docs/overview.md, "Events": added a paragraph on how null-valued arguments behave.

🤖 Generated with Claude Code

The argument helpers used isset(), so an argument set to null counted
as missing: hasArgument() returned false, getArgument() returned the
default, addArgument() overwrote the null value and removeArgument()
left the key in place. Use array_key_exists() instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar

Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

CI fails in "Install PHP dependencies" before any check runs, independent of this change: joomla/console (require-dev) requires joomla/event ^4.0, but the checked-out root package gets a dev-<branch|sha> version that does not satisfy it ("joomla/event dev-… is the root package and cannot be modified"). The scheduled runs on 4.x-dev fail the same way (every run since at least 2026-08-31). Locally, with COMPOSER_ROOT_VERSION=4.0.x-dev, phpunit, phpcs (src) and phpstan pass. Fixing it needs a root version in CI (e.g. COMPOSER_ROOT_VERSION in the shared workflow, or a branch-alias plus enough git history for Composer to guess the version), which is outside the scope of this PR.

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.

1 participant