Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: Stop class execution without terminating the script (Or includes)
    text
    copied!<p>In the class below, I need kill() to end whatever is going on within the class and just stop all and any processes WITHIN the class, not the script:</p> <pre><code>&lt;?php class email { //Expressions const exp_name = "/^[A-Za-z .'-]+$/"; const exp_email = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; const error = "We are sorry, but there appears to be a problem with the form you submitted.&lt;br/&gt;"; private $msg = 'Thank you for subscribing'; protected $status = true; function __construct() { self::validate(); echo '&lt;br/&gt;the CLASS continued&lt;/b&gt;&lt;br/&gt;'; } private function validate() { //Empty fields foreach ($_REQUEST as $key =&gt; $value) { $val = str_replace( ' ', '', $value ); if ( $val === '' ) { self::error( 'empty', $key ); self::kill(); //If empty, this should end the loop and class } //if:empty } //foreach //Validate Name if( !preg_match(self::exp_name,$_POST['Name']) ) { self::error( 'name' ); self::kill(); //kill //Validate e-Mail if( !preg_match(self::exp_email,$_POST['e-Mail']) ) { self::error( 'email' ); self::kill(); //kill } } public function status() { return $this-&gt;status; } public function msg() { return $this-&gt;msg; } private function error( $type = null, $value = null ) { switch( $type ) { case 'empty': $this-&gt;msg = self::error . "&lt;div class='error'&gt;&lt;b&gt;The following field is empty: &lt;/b&gt;" . $value . "&lt;/div&gt;"; self::set( false ); break; case 'name': $this-&gt;msg = self::error . "&lt;div class='error'&gt;&lt;b&gt;The First Name you entered does not appear to be valid.&lt;/b&gt;&lt;/div&gt;"; self::set( false ); break; case 'email': $this-&gt;msg = self::error . "&lt;div class='error'&gt;&lt;b&gt;The e-Mail you entered does not appear to be valid.&lt;/b&gt;&lt;/div&gt;"; self::set( false ); break; default: self::set( false ); $this-&gt;msg = self::error; } return; //kill app } private function set( $boolean = false ) { $this-&gt;status = $boolean; } private function kill() { //die(); //exit( $this ); //exit(); //return; //break; } } $email = new email(); echo $email-&gt;msg(); echo '&lt;br/&gt;'; echo '&lt;br/&gt;'; echo 'The script continued!!!'; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload