Type hinting
In PHP5 you will be able to indicate that a method must receive an object of some class as an argument.
Example 10: type hinting
<?php
class foo {
// code ...
}
class
bar {
public function process_a_foo(foo $foo) {
// Some code
}
}
$b = new bar();
$f = new foo();
$b->process_a_foo($f);
?>
As you can see the class name can be indicated before the argument name to make PHP5 know that $foo should be
an object of the class foo.
an object of the class foo.
Static members
Static members and static methods can be used to implement terms known in OOP as “class methods”
and “class variables”.
and “class variables”.
A “class method” is a method that can be called without creating an instance of the class.
A “class variable” is a variable that can be accessed without creating an instance of the class (and without
needing a get method)
A “class variable” is a variable that can be accessed without creating an instance of the class (and without
needing a get method)
Example 11: class methods and class variables
<?php
class calculator {
static public $pi = 3.14151692;
static public function
add($x,$y) {
return $x + $y;
}
}
$s = calculator::$pi;
$result = calculator::add(3,7);
print("$result");
?>