PHP learning diary (1)-usage of classes and functions, and php diary. PHP learning diary (1)-usage of classes and functions, php diary 1. UDF functionadd ($ a, $ B) {$ c $ a + $ B; echoaddtest :; echo $ c; return $ c;} add (1, 2); output PHP learning diary (1) -- Use of classes and functions, php diary
I. user-defined functions
function add($a,$b){ $c=$a+$b; echo 'add test:'; echo $c; return $c;}add(1,2);
Output result:
add test:3
II. call functions in the class
1. double colon:, directly called by class name without instantiation
class test{ public function add($a,$b){ $c=$a+$b; echo 'class test:'; echo $c; return $c; }}test::add(1,2);
2.->, used by the instantiated object
class test{ public function add($a,$b){ $c=$a+$b; echo 'class test:'; echo $c; return $c; }}$object=new test();$object->add(1,3);
Usage (1) -- Use of classes and functions, php diary I. user-defined function add ($ a, $ B) {$ c = $ a + $ B; echo 'add test: '; echo $ c; return $ c;} add (1, 2); output...