Nothing is safe if you do not know what you are doing. Almost all of the websites on the internet today are insecure because almost all are made by people who think they can decorate a cake recipes and this is enough to make a website.
Interestingly in desktop systems that do not involve internet security can often be overlooked without major problems. But these people who do not know what they are doing prefer to do to the web, even by not even knowing that the best solution probably is for the same desktop, or mobile. Web should be the last option when the others are not appropriate. That is, it is a sum of errors.
Do not just answer this question to keep you safe. And everyone thinks this is enough and a half dozen and that's all right. Security is a mobile target, it always changes, so you can only make sure you understand a lot of computing.
To answer this question, yes, it is safe if everything is done right. If you do wrong it is not. To do it right involves a lot, but the main thing is to configure the server properly to process PHP pages always and not expose them. But do not think this is enough.
If everything is correct every request to something with .php
extension will be delivered to the PHP interpreter who will execute the code on the server and will issue a response to the HTTP server that will send it to the browser. So, unless you do something absurdly wrong, almost impossible, nothing in the PHP code will go to the HTTP server and hence to the client. The PHP code is usually mixed with HTML with PHP, only the HTML part and what the programming code generates in the request is going to go to the browser.
The fact of not going to the browser does not mean that it is safe, only that it will not go there in normal conditions.
And do not rely on random people on the internet. There are some myths in the answers posted here, but most are right.