Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:07:44+00:00 2026-06-11T05:07:44+00:00

I’m making a form validation class and it works like this currently. $validator->setVar($_POST[‘Username’]) ->standardFilter(array(‘XSS’,

  • 0

I’m making a form validation class and it works like this currently.

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

While it works perfectly when chained like this, I can’t archieve the following result.

$validator->setVar($_POST['Username'])
          ->isValidEmail()
          ->isValidPhoneNumber()
          ->isSet()
          ->isNull()
          ->getResult()

For example, script returns the following values

->isValidEmail() (true)
->isValidPhoneNumber() (true)
->isSet() (false)

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.)

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.

How can I archieve this in PHP?

TL;DR:

var_dump($validator->setVar('Test message')->isInteger()->setTrue());
                                             //false     //true

Output: false, because once isInteger() failed, rest of the chain isn't executed.

How can I archieve this in PHP?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:07:45+00:00Added an answer on June 11, 2026 at 5:07 am

    Try something like this

    class FooBar
    {
      private $SomethingWrong = false;
    
      function Bar()
      {
        if( $this->SomethingWrong )
          throw new Exception('SomeThing is wrong');
        return $this;
      }
    
      function Foo()
      {
        return $this
      }
    }
    
    $foobar = new FooBar();
    $foobar->Bar()
           ->Foo();
    

    The Foo() part will not be executed, because of the exception in the Bar().

    Of course, there are some variations. If you do not want a exception, but a silent non-execute, you could try this:

    class FooBar
    {
      private $SomethingWrong = false;
    
      function Bar()
      {
        $this->SomethingWrong = true;
        return $this;
      }
    
      function Foo()
      {
        if( !$this->SomethingWrong )  {
          // do my stuff
        }
        return $this
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.