uuid: - value: 8ee882f8-f25b-4ae7-9dc3-aedc78ee0998 langcode: - value: en type: - target_id: daily_email target_type: node_type target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7 revision_timestamp: - value: '2025-05-11T09:00:07+00:00' revision_uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 revision_log: { } status: - value: true uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 title: - value: 'Named arguments add context' created: - value: '2024-08-26T00:00:00+00:00' changed: - value: '2025-05-11T09:00:07+00:00' promote: - value: false sticky: - value: false default_langcode: - value: true revision_translation_affected: - value: true path: - alias: /daily/2024/08/26/named-arguments-add-context langcode: en body: - value: |
A couple of weeks ago, I wrote that using types adds context to code, making it easier to read and understand.
Something else that also adds context is named arguments, which were introduced to PHP in version 8.0.0.
I particularly like them when making assertions within tests, where getting the expected and actual values in the wrong order can create some confusing output.
For example:
self::assertSame(expected: 'My Drupal website', actual: $node->label());
While I can tell from the assertion that I'm checking two values are the same, adding the argument names makes it clear which is the expected value and which is the actual value.
In fact, if you use named arguments, the order no longer matters, so I can put them in whichever order I want and it will work the same way.
format: full_html processed: |A couple of weeks ago, I wrote that using types adds context to code, making it easier to read and understand.
Something else that also adds context is named arguments, which were introduced to PHP in version 8.0.0.
I particularly like them when making assertions within tests, where getting the expected and actual values in the wrong order can create some confusing output.
For example:
self::assertSame(expected: 'My Drupal website', actual: $node->label());
While I can tell from the assertion that I'm checking two values are the same, adding the argument names makes it clear which is the expected value and which is the actual value.
In fact, if you use named arguments, the order no longer matters, so I can put them in whichever order I want and it will work the same way.
summary: null field_daily_email_cta: { }