PHP learning diary (1) -- usage of classes and functions, php diary _ PHP Tutorial

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

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.