The Oop of PHP notes

Source: Internet
Author: User
The Oop of PHP notes

├ the properties and methods of object access itself are accessed with "--", and no "$" is required to access the property;
├ class inside Use this keyword when you add "$" before this $this->name = "Firstep";
├ class constructor __construct () destructor __destruct ()
├ access modifier public protected (this class, subclass, parent class accessible) private
├ Package correlation function (get\set) __set ($PN, $PV) __get ($arg) private properties for modification or access need to implement both methods
├ inherit using keyword extends, subclass Access Parent class resource "parent class:: Parent class Internal member"
├ abstract, the class with abstract method must be abstract class, abstract class must have abstract method, abstract method definition cannot have the implementation, abstract method must add abstract before;
├ subclasses of abstract classes must overload all abstract methods of an abstract class
├ keyword final, the class cannot be inherited when the class is defined, and the method cannot be overloaded when it is used to define a method
├ keyword self: Used to access resources in a class, with this type, but self does not instantiate to access the internal members of the class, generally used to access static members in the class, Constants (self:: Class internal members)
├ Static member Access, class name:: Static member, similar to C + +
├ Keyword const: can only be used to define attribute members
├ Interface (interface): A special abstract class in which the member attributes are all abstract or constant, the methods are all abstract, the abstract methods are not abstracted, the access rights of the abstract methods are public, and the member properties are const constants.
├ interface Implementation (implements) is similar to Java
├php and Java are all single-inheritance implementations
├ Object Type Judge instanceof, usage is similar to Java; if (object instanceof class name)
├ Object __tostring (), automatically call the ToString method when printing a class similar to Java
├ automatically load object function __autoload ($class _n) {include ($class _n. "). PHP ");
├ Object exception handling function __call ($n, $v) {print "functionname:". $n; Print "Func args:". Print_r ($V)}
?
?
Abstract class animal{
Private $color;
function __construct ($color = "") {
$this->color = $color;
}
function __set ($n, $v) {
$this $n = $v;
}
function __get ($color) {
return $this->color;
}
function Run () {
Print "Animal is running ...";
}
Abstract function sleep ();
}
Class Cat extends animal{
function Run () {
Animal::run ();//Subclass Calling method of parent class
Print "Cat is running ...";
}
function sleep () {
Print "Cat is sleep ...";
}
}
$cat = new Cat ("Whilte");
Print $cat->color. "
";
$cat->color = "BLACK";
Print $cat->color. "
";
$cat->run ();
  • 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.