Underscores are replaced with hyphens and case ignored in user.txt

When I save data to a user’s user.txt file, underscores in the key are replaced with hyphens and the case is ignored. For example:

$user->update(['some_key' => 'value']);

results in:

// user.txt
Some-key: value

Retrieving that data using the original key that is all lowercase and contains underscores works fine, however. Like so:

echo $user->content()->get('some_key')
// value

Why is case ignored and why are underscores replaced with hyphens in the user.txt file but then interpreted to be the same as underscores? Is there anyway to prevent this behavior?

No, that is expected behavior. Don’t really know why.

It’s not just user files, every Kirby content file uses this format.

The original reason we went for this normalization in Kirby 1 was to ensure that content files can be edited by hand. The first versions of Kirby 1 didn’t have a Panel, that was added later. So it was important that fields still work even if the field name is not written exactly as defined.

We kept this behavior mainly for backwards-compatibility and because editing content files outside of the Panel is still an official feature that we want to make as non-technical as possible.

@lukasbestle Thank you very much for the clarification. That makes sense.