PHP learning diary (1) -- Use of classes and functions

Source: Internet
Author: User
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.