《PHP与MySQL程序设计》面向对象的PHP

WBOY
Release: 2016-06-23 14:29:29
Original
949 people have browsed it


PHP对象的方法、属性的访问跟Java相似,有public, protected, private, final, static。

6.3 构造函数和析构函数

function __construct/destruct(args...) {

     ...

6.4 静态类成员

class Visitor {

     private static $visitors = 0;

     function f() {

          self::$visitors++;

     }

     static function getVisitors() {

          return self::$visitors;

     }

6.5 instanceof和其他辅助函数(类似Java反射)

PHP不支持的OOP特性:

方法重载,运算符重载,多重继承。

7.2 对象克隆

PHP4将对象视为数据类型,PHP5默认将对象视为引用。

$obj1 = clone $obj2;

重写对象的_clone方法调整克隆行为。

7.3 继承

class Employee { ... }

class Executive extends Employee { ... }

class CEO extends Executive { ... }

构造函数:

function __construct($name) {

     parent::__construct($name);

     echo "

CEO created!

";

7.4 接口

interface interfaceName {

     CONST 1;

     CONST N;

     function method1();

     function method2();

class Class_name implements interfaceName {

     function method1() {

          ...

     }

     function method2() {

          ...

     }

7.5 抽象类

abstract class Class_Name {

     ...


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!