Skip to content

Instantly share code, notes, and snippets.

@chrishieu
Created February 9, 2023 17:00
Show Gist options
  • Save chrishieu/e789d8c42c13f1151c947f054635ecd2 to your computer and use it in GitHub Desktop.
Save chrishieu/e789d8c42c13f1151c947f054635ecd2 to your computer and use it in GitHub Desktop.
<?php
class TextInput {
// Properties
public $value;
// Methods
function add($text) {
$this->value .= $text;
}
function getValue() {
return $this->value;
}
}
class NumericInput extends TextInput{
// Methods
function add($text) {
if (is_numeric($text)) {
$this->value .= $text;
}
}
}
$input = new TextInput();
$input->add('1');
$input->add('a');
$input->add('0');
echo $input->getValue().PHP_EOL;
$input2 = new NumericInput();
$input2->add('1');
$input2->add('a');
$input2->add('0');
echo $input2->getValue();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment