PHP learning diary (1) -- usage of classes and functions 1. UDF functionadd ($ a, $ B) {$ c $ a + $ B; echoaddtest :; echo $ c; return $ c;} add (1, 2); output result: addtest: 3 & nbsp; 2. call the Function & nbsp; 1. double colon ::, you don't need to instantiate it. you can call class PHP learning diary directly by class name (1) -- Use of classes and functions
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 );