Tuesday, June 25, 2013

PHP TYPE HINTING

PHP TYPEHINTING

Functions are now able to force parameters to be objects.
<?php
// An example class
class MyClass {
    public $var = 'Hello World';
}

/**
 * A test function
 *
 * First parameter must be an object of type MyClass
 */
function myFunction(MyClass $foo) {
    echo $foo->var;
}

// Works
$myclass = new MyClass;
myFunction($myclass);
?>

No comments:

Post a Comment