class Namestring {
   var $name;
   var $nameLength;
   var $checksum;

   function __construct($string_in) {
      $this->name = $string_in;
      $this->nameLength = strlen($string_in);
      $this->checksum = $this->computeChecksum($string_in);
   }

   function setName ($new_string) {
      $this->name = $new_string;
      $this->nameLength = strlen($new_string);
      $this->checksum = $this->computeChecksum($new_string);
   }

   function computeChecksum ($string) {
      // w praktyce niezbyt dobra suma kontrolna
      $sum = 0;
      for ($x = 0;
         $x < strlen($string);
         $x++) {
            $sum += ord($string[$x]);
      }
      return($sum % 100);
   }

   function selfTest () {
      // zwraca FALSE jeli wszystko jest dobrze
      if ($this->nameLength != strlen($this->name)) {
         return("Nazwisko $this->name nie skada si ". "z $this->nameLength");
      }
      elseif
         ($this->checksum != $this->computeChecksum($this->name)) {
         return("Nazwisko $this->name suma kontrolna si nie zgadza!");
      }
      else {
         return(FALSE);
      }
   }
}

class NonTestingObject {
}

class ObjectTester {
   function ObjectTester() {
      // pusty konstruktor
   }

   function test ($thing) {
      if (is_object($thing)) {
         if (method_exists($thing, 'selfTest')) {
            $this->handleTest(call_user_method('selfTest', $thing));
         }
      }
      elseif (is_array($thing)) {
         foreach ($thing as $component) {
            $this->test($component);
         }
      }
      // zignoruj jeli nie ma tablicy lub obiektu
   }

   function handleTest ($result) {
      if ($result) {
         print("Ostrzeenie: $result");
      }
   }
}
