Thứ Tư, 1 tháng 1, 2025

PHP OOP - Classes and Objects

 class MyClass

{

    // Declare a public constructor

    public function __construct() {

        echo'0000';

    }


    // Declare a public method

    public function MyPublic() {

        echo'11111';

    }


    // Declare a protected method

    protected function MyProtected() {

       echo'2222';     

    }


    // Declare a private method

    private function MyPrivate() { 

       echo'3333';     

    }


    // This is public

    function Test()

    {

        $this->MyPublic();

        $this->MyProtected();

        $this->MyPrivate();

    }

}

Select 1:

$apple = new MyClass();

$apple ->Test();

Select 2:

MyClass::Test();


Không có nhận xét nào:

Đăng nhận xét