Gatekeeper in macOS ensures only verified applications can be executed and this is achieved by signing the application using codesign. Code signing is mandatory in macOS Monterey.
PHP module installed using homebrew is not signed, so you need to sign it first before it can be used, or you will get the error
https://www.simplified.guide/macos/apache-php-homebrew-codesign