Hi all,
I am building an assertType object using static functions. What I want to
keep away from is the following:
<code>
public static function assertString($para){
return $answer;
};
public static function assertBool($para){
return $answer;
};
...
public static function assertArray($para){
return $answer;
};
</code>
What I would like to do is replace this with the following:
<code>
if (!class_exists('TypeAssert')) {
class TypeAssert {
private static $types = array(
'array','bool','float','integer','null','numeric',
'object','resource','scalar','string'
);
public static function __call($method,$arguments) {
$obj = self::assertStandardTypes($arguments[0]);
return $obj->$method;
}
public static function assertStandardTypes($para) {
$r = TypeAssert::getTypesObject();
if (is_array($para)) $r->array = true;
if (is_bool($para)) $r->bool = true;
if (is_float($para)) $r->float = true;
if (is_integer($para)) $r->integer = true;
if (is_null($para)) $r->null = true;
if (is_numeric($para)) $r->numeric = true;
if (is_object($para)) $r->object = true;
if (is_resource($para)) $r->resource = true;
if (is_scalar($para)) $r->scalar = true;
if (is_string($para)) $r->string = true;
return $r;
}
public static function getTypesObject() {
$obj = (object) '';
for ($i = 0; $i < count(self::$types); $i++) {
$obj->{self::$types[$i]} = (bool) false;
}
return $obj;
}
}
}
echo('<pre>');
echo(TypeAssert::string('test'));
echo('</pre>');
</code>
I don't think this is possible (see
http://marc.info/?l=php-general&m=114558851102060&w=2
). But I would LIKE for it to work (currently, the above code doesn't).
Anybody have any insight on how I might get this to work?
Thanks!
--
Jared Farrish
Intermediate Web Developer
Denton, Tx
Abraham Maslow: "If the only tool you have is a hammer, you tend to see
every problem as a nail." $$