P粉4481302582023-09-04 13:32:01
phpdotenv is poor at error reporting (and I personally think it also doesn't rely properly on standards and best practices, which can lead to a number of side effects, including the caveats you encountered - it's just that I'm fairly sure their authors thought this is a feature rather than a bug, so I have to admit I won't judge them, at the end of the day, users need to work on themselves and understand what they are doing).
For your specific problem, if you use a library, learn how to configure it. Even my previous comment might prompt you that it might not be suitable, actually - and this is where phpdotenv shines - it's doing most of the heavy lifting and you can control most of the parts --- just not the file format.
Your problem is not the file format. So configure your application correctly to take parameters from any environment and handle error conditions (for example, throwing on unexpected values at the beginning). This should also reveal what mistakes you made when using this or that library, and fix it in your code.