《PHP與MySQL程式設計》物件導向的PHP

來源:互聯網
上載者:User
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 {

...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.