PHP Programming/OOP5/Input Validation

This is an example using the power of OOP with PHP5. This example can be used to validate different user inputs. This was moved by Wykis from Kgrsajid's example on Programming:PHP.

interface Validator
{
  public function validate($value);
  public function getError;
}

abstract class AbstractValidator implement Validator
{
  protected $errors = array;
  public function __construct
  {
    // Do Something
  }

  public function getError
  {
    return $this->errors;
  }
}

class BooleanValidator extends AbstractValidator
{
  public function __construct
  {
    // Do Something
  }

  public validate($value)
  {
    $return = literalize($value);
    if (!is_bool($value))
    {
      $this->errors[] = 'invalid_boolean';
      return false;
    }
    return true;
  }
}

  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.

PHP_Programming/OOP5/Input_validation
 



 

Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.


Manage research, learning and skills at defaultLogic. Create an account using LinkedIn or facebook to manage and organize your Digital Marketing and Technology knowledge. defaultLogic works like a shopping cart for information -- helping you to save, discuss and share.


  Contact Us