PhpType.class.php
<?php ?>
EBadType.class.php
<?php abstract class PhpType { protected $_var; abstract protected function _check(); public function __construct($_var) { $this->_var=$_var; if(!$this->_check()) throw new EBadType('Bad Type'); } public function __get($_name) { return $this->_var; } public function __set($_name, $_val) { $ret=$this->_var; $this->_var=$_val; return $ret; } } ?>
IntType.class.php
<?php class EBadType extends Exception { } ?>
I tak dalej już idą typy. Jeżeli chcecie całość to proszę pisać na pw, a wyśle spakowane na maila.
<?php class IntType extends PhpType { protected function _check() { } } ?>
Tutaj test
Proszę o ocene i ewentualne komentarze, pomysły.
<?php function requiresint(IntType $_int) { $_int->var=8; } require_once('types/init.php'); $int=new IntType(5); $bln=new BooleanType(TRUE); try { $res=new ResourceType(NULL); } catch (EBadType $e) { } requiresint($int); // OK requiresint($bln); // BŁĄD php ?>