= $arr['class'] . '.';
$args = array ();
if (!empty ($arr['args']))
foreach ($arr['args']as $v)
{
if (is_null($v))
$args[] = 'null';
elseif (is_array($v))
$args[] = 'Array[' . sizeof($v) . ']';
elseif (is_object($v))
$args[] = 'Object: ' . get_class($v);
elseif (is_bool($v))
$args[] = $v ? 'true' : 'false';
else
{
$v = (string)@$v;
$str = htmlspecialchars(substr($v, 0, $MAXSTRLEN));
if (strlen($v) > $MAXSTRLEN)
$str .= '...';
$args[] = '"' . $str . '"';
}
}
$s .= $arr['function'] . '(' . implode(', ', $args) . ')';
$line = (isset ($arr['line']) ? $arr['line']: 'unknown');
$file = (isset ($arr['file']) ? $arr['file']: 'unknown');
$s .= sprintf(' # line %4d, file: %s', $line, $file);
CHAPTER 3 ?– STARTING THE TSHIRTSHOP PROJECT 54
$s .= "\n";
}
return $s;
}
}
?>
?– Note You??™ll learn more about object-oriented programming concepts and PHP in the following chapters.
For now, we??™d like just to draw attention to the class constructor, a special function named __construct().
If you type in this code by hand, notice the function name is prefixed by two underscore symbols, not one.
Overlooking this detail is a common source of errors in PHP 5 scripts.
4. Modify the index.php file to include the newly created error_handler.php file, and set the error handler:
// Include utility files
require_once 'include/config.
Pages:
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125