<?php
# function name does not case sensitive, but variable name does
// function plus(integer $a, integer $b) { <-- WRONG!!!
// here integer should be a class
function plus($a,$b) {
return $a+$b;
}
function mul($a, $b) {
return $a*$b;
}
?>
#!/usr/bin/php
<?php
// if head.inc was not be found, require() will cause a fatal error, but include() will
// cause a warning
// use require_once/include_once to avoid from include a file more than one time
require_once('head.inc');
echo plus(3,4)." ";
echo mul(3,4)." ";
echo "------- ";
# scope
# P.S. code block {} does nothing about scope
$x=3;
function a() {
echo $x." "; // $x is a global variable,
// but it non-visible here
// except $x is a super global variable
}
a();
echo $x." ";
# make a variable to be global
function b() {
global $y; // export $y to be global
$y=4; // assigned after global declaration
echo "$y ";
}
b();
echo "$y ";
# default value
function c($z=5) {
echo "$z ";
}
c();
c(6);
?>