Created
February 9, 2023 17:00
-
-
Save chrishieu/e789d8c42c13f1151c947f054635ecd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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