TLTypeException Class Reference

Built-in exception for type errors. This exception can be thrown when a variable is expected to have a certain type, but the type does not match. More...

List of all members.

Public Member Functions

 __construct ($expectedType, $gotVar, $varName=null)
 Construct a new TypeException.


Detailed Description

Built-in exception for type errors. This exception can be thrown when a variable is expected to have a certain type, but the type does not match.

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.


Constructor & Destructor Documentation

TLTypeException::__construct ( expectedType,
gotVar,
varName = null 
)

Construct a new TypeException.

Parameters:
$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.

Definition at line 772 of file tlib.php.


The documentation for this class was generated from the following file:
Generated on Sun Sep 24 22:05:25 2006 for TLib-PHP by  doxygen 1.4.7