intelephense error on VS Code: Expected type 'string'. Found 'string[]'

Global variables can be a little bit wonky in intelephense, an issue already exists to improve the support. In this specific case, the type that is inferred is determined by the first assignment. Since that is the explode statement, it'll assume $dest is an array of strings.

There are a couple of solutions to this:

  • Make sure to intelephense what the type of $dest is with comments.

    function transfer(string $file)
    {
        /** @var string $dest */
        global $dest;
    }
    
  • Make sure the first assignment of $dest actually is a string:

    $tempdest = explode('\\', SOURCE_PATH);
    $tempdest[count($tempdest) - 2] = 'ToUpload';
    $dest = implode('\\', $dest);