Chained PHP controls
<p>I'm making a form validation class and it works like this currently.</p>

<pre><code>$validator-&gt;setVar($_POST['Username'])
          -&gt;standardFilter(array('XSS', 'SQL_INJECTION'))
          -&gt;customRegex()
          -&gt;replace('This', 'With this')
          -&gt;getResult();
</code></pre>

<p>While it works perfectly when chained like this, I can't archieve the following result.</p>

<pre><code>$validator-&gt;setVar($_POST['Username'])
          -&gt;isValidEmail()
          -&gt;isValidPhoneNumber()
          -&gt;isSet()
          -&gt;isNull()
          -&gt;getResult()
</code></pre>

<p>For example, script returns the following values</p>

<pre><code>-&gt;isValidEmail() (true)
-&gt;isValidPhoneNumber() (true)
-&gt;isSet() (false)
</code></pre>

<p>Basically, I'm going to make an array, fill it with true/false depending on the result of each function, and I'll look for a specific value in array (a false). If it exists, the class will return false regardless of the rest of the chains. (or I can just override variables, not important here.)</p>

<p>However, I want $validator to stop chaining once it gets a false from a function. Let's say it received a false from isSet(). It shouldn't execute isNull() and getResult() since we already have a failed check.</p>

<p>How can I archieve this in PHP?</p>

<p><strong>TL;DR:</strong></p>

<pre><code>var_dump($validator-&gt;setVar('Test message')-&gt;isInteger()-&gt;setTrue());
                                             //false     //true

Output: false, because once isInteger() failed, rest of the chain isn't executed.
</code></pre>

<p>How can I archieve this in PHP?</p>
