PHP class declaration and PHP Class usage example sharing _php tutorial

Source: Internet
Author: User
Tags php language php class
Copy CodeThe code is as follows:

/**php language is support object-oriented programming, for object-oriented programming, learn Java and C + + people know Ah!
* If you are not clear to Baidu to ask about it.
*/

Let's define a class that defines the class's keyword as "class".
Class Computer {

Inside a class you can create methods, variables, etc.

Define an addition
function Add ($n 1, $n 2) {

$sum = $n 1 + $n 2;
return $sum;
}
Define a subtraction
function JF ($n 1, $n 2) {

$sum = $n 1-$n 2;
return $sum;
}
Define a multiplication
Function CF ($n 1, $n 2) {

$sum = $n 1 * $n 2;
return $sum;
}
}

/**
How to use a method in a class is to create an object of the class and invoke the method with the object
Here's how to call the class
*/

$com is the object of the computer class, creating the object with the New keyword
$com = new computer ();

Call a method in a class with the object name, the method name (parameters, Parameters ...). )
echo $com add;
Echo $com, JF;
echo $com CF (.)

These methods are called by the button, you can simply write a calculator,
Each button corresponds to a method
?>

http://www.bkjia.com/PHPjc/746865.html www.bkjia.com true http://www.bkjia.com/PHPjc/746865.html techarticle Copy the code as follows:? PHP/**php language is to support object-oriented programming, for object-oriented programming, learn Java and C + + people know Ah! * If not clear to Baidu ask ...

  • 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.