Public Member Functions | |
__construct ($expectedType, $gotVar, $varName=null) | |
Construct a new TypeException. |
Example:
function setAge($age) { if (!is_int($age)) { throw new TypeException("int", $age, "age"); } print("You're age is $age"); } function setPerson($person) { if (!is_object($person) || get_class($person) != "Person") { throw new TypeException("object(Person)", $person, "person"); } } setAge("fourty"); $monkey = new Animal("Monkey"); setPerson($monkey);
Results in:
Uncaught exception 'TypeException' with message 'Expected "int", got "string(fourty)"' in [stacktrace] Uncaught exception 'TypeException' with message 'Expected "object(Person)", got "object(Monkey)"' in [stacktrace]
Definition at line 764 of file tlib.php.
TLTypeException::__construct | ( | $ | expectedType, | |
$ | gotVar, | |||
$ | varName = null | |||
) |
Construct a new TypeException.
$expectedType | (string) The type you where expecting (int, string, object(ClassType)) | |
$gotVar | (mixed) The variable you got who's type didn't match. | |
$varName | (string) The name of the variable you got who's type didn't match. |