User Tools

Site Tools


errorhandler_class

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
errorhandler_class [2019/12/21 22:18] – created sahlerrorhandler_class [2021/02/15 20:56] (current) sahl
Line 4: Line 4:
  
 There are also some utility functions for debugging code. There are also some utility functions for debugging code.
 +
 +===== Typechecking =====
 +
 +To introduce semi-strict type checking on functions, the class introduces the ''checkParams()'' which takes a variable number of parameters, but always in pairs of two.
 +
 +One pass a variable to the function and then a type name, and if the variable doesn't match the given type, then an error is triggered.
 +
 +Example:
 +
 +<code php>
 +/**
 + * Display name and age of person.
 + * @param string $name Name of person.
 + * @param int $age Age of person.
 + */
 +function displayNameAndAge($name, $age) {
 +  Errorhandler::checkParams($name, 'string', $age, 'int');
 +  echo $name.' - '.$age.' years.';
 +}
 +</code>
 +
 +This will trigger an error if the ''$name'' and ''$age'' variable isn't of the correct types.
 +
 +==== Types ====
 +
 +The following types can be checked. If anything else is typed it is considered a name of a class.
 +
 +|string|
 +|int|
 +|integer|
 +|float|
 +|array|
 +|resource|
 +|boolean|
 +
 +integer and floats are checked based on content and not variable type, so a string containing a valid integer number will pass as a integer.
errorhandler_class.1576966696.txt.gz · Last modified: 2019/12/21 22:18 by sahl

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki