A settings form can express three separate requests for a nullable label. Leave it unchanged, clear it, or replace it with a string. If the PHP code uses $patch['label'] ?? $current, an explicit null takes the same path as an omitted field. The update can look successful even though the user cannot clear the label.

Prerequisites and example

Use PHP 8.3 CLI. Save this as patch.php. The function accepts an application-level associative array after input decoding and handles one field. Its contract preserves the empty string as a value distinct from null.

<?php
declare(strict_types=1);

function updateLabel(?string $current, array $patch): ?string {
    if (!array_key_exists('label', $patch)) {
        return $current;
    }
    $label = $patch['label'];
    if ($label !== null && !is_string($label)) {
        throw new InvalidArgumentException('label must be a string or null');
    }
    return $label;
}

foreach ([
    [[], 'draft'],
    [['label' => null], null],
    [['label' => ''], ''],
    [['label' => 'ready'], 'ready'],
] as [$patch, $expected]) {
    $actual = updateLabel('draft', $patch);
    if ($actual !== $expected) {
        throw new RuntimeException('unexpected patch result');
    }
    echo json_encode($actual, JSON_THROW_ON_ERROR), PHP_EOL;
}
try {
    updateLabel('draft', ['label' => false]);
    throw new RuntimeException('invalid patch accepted');
} catch (InvalidArgumentException $e) {
    echo $e->getMessage(), PHP_EOL;
}

Run php patch.php. Output values are printed as JSON so the difference between an empty string and null is visible.

"draft"
null
""
"ready"
label must be a string or null

Validate presence before value

array_key_exists reports that the key is present even when its value is null. After checking presence, the function can validate the actual value without emitting an undefined-key warning. Using isset here would erase the distinction this interface needs. A truthiness check would also mishandle strings your contract might allow, such as the empty string or the string 0.

Apply the same distinction when you map the outcome to persistence. An omitted field may mean you should skip writing that column, whereas explicit null may require setting it to database NULL. This sample computes a value and does not perform a database update. If you need to express the difference downstream even when the prior value is already null, carry a separate presence flag or build the list of columns to update from the request.

If a client still cannot clear the field, inspect the decoded request immediately before the adapter. Filters that remove nulls or empty values can discard the intent before it gets here. For a JSON endpoint validate that the request has the required object shape before mapping it into a PHP array, and decide separately what to do with unknown keys. If older PHP code passes an object directly to array_key_exists, migrate this boundary to an array contract. Direct object arguments are no longer supported as of PHP 8.0.

Reference: PHP array_key_exists reference and changelog. More PHP tutorials.