Bug: a function defined in config.php causes random breakage

I want my config to load some data from environment variables. So I changed it like so:

<?php

function getenv_or_default($name, $default) {
    $v = getenv($name);
    if ($v !== false) {
        return $v;
    }
    return $default;
}


return [
    'debug' => true,
];

Just adding this (unused) definition breaks the app in weird ways: for example, now whenever I go to change a page status in the panel (draft → listed), I get a JSON output.

This took me way too long to figure out that it was because Kirby really doesn’t like functions to be defined in config.php

welcome to the forum.

you could define the function in your index.php file before instanciating kirby or try my plugin which explains how to use it in config files in its readme.