Following on from @Scofield's solution for docker, here is a solution for ddev (assuming linux/macOS/WSL):
First, as before create an executable file
sudo touch /usr/local/bin/php
sudo chmod +x /usr/local/bin/php
Second, modify the contents of that file, inserting the following and save:
#!/bin/bash
ddev php $@
Third, add a reference to this newly created file to your settings.json
as follows:
"php.validate.executablePath": "/usr/local/bin/php",
This key may already exist with an empty value, in which case, update it to match the above.
When complete the built-in PHP validation and debugging within VS Code should be possible without errors.