It is important to know if you are using a flexible or standard environment since flex environment is compatible with PHP 7.2 and 7.3 runtimes, and standard is compatible with PHP 8.1, but in its preview phase , . You can use PHP 8.1 in flex environment, but you need to use custom runtimes  and provide a custom Docker image or Dockerfile from the open source community.
How to know if you are in a Standard or Flexible environment:
In your app.yaml, find the runtime line.
If it looks similar to the following:
runtime: php81 # Replace with php74 to use PHP 7.4
Then you are running under a standard environment .
And if it looks like this other example:
Then you are using a flexible environment for the deployment .