PHP: is it possible to end the script as exit (), but from within the php class / object

Can this be done?

$objetc -> runAndFinish(); echo "this should not be echoed"; 

instead of this?

 $objetc -> runAndFinish(); exit(); echo "this should not be echoed"; 

So runAndFinish (); the method will somehow complete the processing of the script. Is it possible?

+4
source share
3 answers

Put the output (); inside your classes runAndFinish (); Method

 class someClass{ function runAndFinish(){ exit(); } } $obj = new someClass(); $obj->runAndFinish(); echo "not gonna print"; 
+10
source

Put exit call in method and it will exit when it is called

+5
source

Yes, of course, it is possible. It puts exit() or die() (or something else that might end up executing) in this particular method, and it will execute.

As far as I know, there are no special restrictions for what you can execute in methods against anything else.

0
source

Source: https://habr.com/ru/post/1335277/


All Articles