PHP Object-oriented applications

Source: Internet
Author: User

<?php

classMyClass { // 定义MyClass类    public$name; // 定义了一个公有属性    protected$_age; // 定义了一个保护属性    private$_email; // 定义了一个私有属性        publicfunctionmy_method() { // 定义my_method方法    }        protectedfunction_my_method2() { // 定义_my_method2方法    }}$obj= newMyClass; // 实例化$obj->name = ‘noname‘; // 设置name属性$obj->_age = 12; // 这是错误的,不能设置保护属性$obj->address = ‘King Street.‘// 设置一个未声明的属性是允许的,效果和公有属性类似,但未赋值前不能使用。$obj->my_method() // 调用公有方法$obj->_my_method2(); // 这是错误的,不能调用保护方法Method calls in------------------------------------------interfaces and static classes can be directly:

Class Person
{
public static function Sayname ()
{
echo "hello!";
}
}
Class Emplyee extends person{

}
Person::sayname ();

----------------------------------------------

Interface declaration and invocation in PHP

<?phpinterface a{           //Declaration A Interface  //Declare a constant in the interface  const B = ' The value of the constant in the interface is: Interface CONSTANT value ';} echo a::b;             Output interface constant?>

PHP Object-oriented applications

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.