Type Hinting
Type Hinting is a new concept introduced in PHP5,
Which is forcing the function parameter to be and object or an array.
A parameter can be forced to be an object by specifying the name
of the class in function prototype
Eg
<?php
Class ClassA
{
function get_values(ClassB $obj_class_b)
{
…………..
}
}
Class ClassB
{
public var $a = ‘hello’;
}
$obj_class_a = new ClassA;
$obj_class_b = new ClassB;
$obj_class_a = get_values(’hai’);
//output: Fatal Error: Argument 1 must be an object of class ClassB
$obj_class_a = get_values(’hai’);
$foo = new stdClass;
$obj_class_a = get_values($foo); /// Sending object of some other class
//output: Fatal Error: Argument 1 must be an instance of ClassB
$obj_class_a->get_values(null);
// output: Fatal Error: Argument 1 must not be null
$obj_class_a->get_values($obj_class_b);
/// will work fine
?>
