title: How to implement a function that adds to a class' string and another function that returns it in php?
body: <p>I am working on this problem:</p>
  
  <p>The user interface contains two types of user input controls: TextInput, which accepts all texts and NumericInput, which accepts only digits.</p>
  
  <p>Implement the class TextInput that contains:</p>
  
  <p>Public function add($text) - adds the given text to the current value.
  Public function getValue() - returns the current value (string).</p>
  
  <p>Implement the class NumericInput that:</p>
  
  <p>Inherits from TextInput.
  Overrides the add method so that each non-numeric text is ignored.
  For example, the following code should output '10':</p>
  
  <pre><code>$input = new NumericInput();
  $input-&gt;add('1');
  $input-&gt;add('a');
  $input-&gt;add('0');
  echo $input-&gt;getValue();
  </code></pre>
  
  <p>Now, I thought the following would be sufficent enough to implement the TextInput class as a minimum as the instructions say</p>
  
  <p>
  
  <pre><code>class TextInput
  {    
      private $str = '';
  
      public function add($text) {
          $str .= $text;
      }
      public function getValue() {
          return $str;
      }
  }
  
  class NumericInput extends TextInput
  {
  
      public function add($text) {
          if ( is_numeric($text)) {
              $str .= $text;
          }
      }
  }
  </code></pre>
  
  <p>It doesn't seem to be working but I thought at the very least the part for class TextInput was done correctly.</p>