PHP Object-oriented------------classes and objects

Source: Internet
Author: User

<?php
Header ("Content-type:text/html;charset=utf-8");
/* $code = $_post["code"];
$name = $_post["Name"];*/
Classes and objects
A class is an abstraction of an object that is an instantiation of a class
Class Ren
{
Member variables
var $shengao;
var $tizhong;
var $name;
var $sex;
Member Properties---The PHP language is not
Member Methods
function Eat ()
{
echo "Eat with your Hand";
}
function Zoulu ()
{
echo "with feet, running, no";
}
}
To create an object, you must have a class
$wo =new Ren ();//Call class
$wo->name= "Zhang San";
echo $wo->name. " <br> ";

example, the area of the shaded portion of a circle with a different radius of two
Idea One: Layering

  $R  =10;   $r  =5 //  large circle area   $S  =3.14* $R  *  $R   //   $s  =3.14* $r  *  $r   //  shaded area   $sss  = $S -  $s   echo   $sss ; 

Idea two: Object-oriented

classcircle{var $r;//This radius belongs to the Circle classfunctionS () {$a=3.14*$this->r*$this->r;//$this->r represents the radius of this objectreturn $a;//you can return only values, and you cannot return other}}//Class Instantiation Object$dayuan=NewCircle ();//the object calls the class, and some of the classes can be called$dayuan->r=10;$DM=$dayuan-S ();$xiaoyuan=NewCircle ();$xiaoyuan->r=5;$XM=$xiaoyuan-S ();Echo($DM-$XM); //In the future, priority is given to object-oriented, that is, the subject involves two "circles" (objects), only a kind of "circle", create Class circle. 

?>

PHP Object-oriented------------classes and objects

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.