Last active
December 30, 2015 04:08
-
-
Save visb/7773528 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| abstract class TypeObject | |
| { | |
| protected $type; | |
| protected $value; | |
| public function __construct($value) | |
| { | |
| $this->setType(strtolower(get_called_class())); | |
| $this->setValue($value); | |
| } | |
| public function equal(TypeObject $object) | |
| { | |
| return $this->getType() == $object->getType() && $this->getValue() == $object->getValue(); | |
| } | |
| public function setValue($value) | |
| { | |
| $this->value = $value; | |
| return $this; | |
| } | |
| public function getValue() | |
| { | |
| return $this->value; | |
| } | |
| protected function setType($type) | |
| { | |
| $this->type = $type; | |
| return $this; | |
| } | |
| public function getType() | |
| { | |
| return $this->type; | |
| } | |
| } | |
| class Int extends TypeObject | |
| { | |
| public function setValue($value) | |
| { | |
| $value = (int) $value; | |
| return parent::setValue($value); | |
| } | |
| } | |
| function load_type($type) { | |
| // carrega o arquivo de $type | |
| } | |
| function call_type($type, $value) | |
| { | |
| if (!class_exists($type)) { | |
| load_type($type); | |
| } | |
| return (new $type($value)); | |
| } | |
| $types = array('number', 'int', 'float', 'double', 'string'); | |
| foreach($types as $type) { | |
| eval("function {$type}(\$value) { | |
| return call_type(__FUNCTION__, \$value); | |
| }"); | |
| } | |
| if (Int(1)->equal(Int(1))) { | |
| echo Int(1)->getType(); | |
| } else { | |
| echo 'false'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment