PHP class declarations and examples of PHP class use methods

Source: Internet
Author: User
Tags php language php class

  This article mainly introduces the PHP class declaration and the PHP class uses the method example, needs the friend to be possible to refer to under

  Code as follows: <?php      /**php language is to support object-oriented programming, for object-oriented programming, Learning Java and C + + people know Ah!       * If you are not clear to Baidu to ask about it.    /        //We define a class, the keyword of the definition class is "class"         class computer {         //within class can create methods, variables etc          //define an addition       &NB Sp function Add ($n 1, $n 2) {              $sum = $n 1 + $n 2;         &N Bsp   return $sum;        }                //define a subtraction         function JF ($n 1, $n 2) {              $sum = $n 1-$n 2;         &N Bsp   return $sum;                            //define a multiplication         Function CF ($n 1, $n 2) {                         $sum = $n 1 * $n 2;             return $sum;                               }      /**     How to use the methods in the class, you need to create the object of the class, use the object to invoke the method     Below is the method to invoke the class    /     / /$com is the object of the computer class, creating objects with the New keyword     $com = new computer ();      //calling methods in the class with   object name-> method name (parameter, parameter ...) )     echo $com-> Add (1,2);     Echo $com-> JF (1,2);     echo $com-> CF (1,2);      //These methods are called by the button, you can simply write a calculator,    //each button corresponding to a method?>  

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.