Lecture Web technology and online services: Lesson 5.2 - Advanced PHP

Lecture "Web Technology and online services: Lesson - Advanced PHP" provide students with knowledge about: Object oriented programming in PHP; Defining (declaring) a class; Accessing properties and methods; Constructors and destructors; . Please refer to the detailed content of the lecture! | ADVANCED PHP 1 Content Contents Objects Defining objects Inheritance Sessions and session variables Object oriented programming in PHP PHP like most modern programming languages C Java JavaScript etc. supports the creation of objects. Creating an object requires you to first define an object class containing variables and or function definitions and then using the new keyword to create an instance of the object class. Note that the object must be defined before you instantiate it. Defining declaring a class Use the class keyword which includes the class name case-insensitive but otherwise following the rules for PHP identifiers . Note The name stdClass is reserved for use by the PHP interpreter. Declaring a class cont. Properties and functions can be declared as public accessible outside the object s scope private accessible only by methods within the same class or protected accessible only through the class methods and the class methods of classes inheriting from the class. Note that unless a property is going to be explicitly declared as public private or protected it need not be declared before being used like regular PHP variables . Declaring a class cont. Classes can also have their own constants defined using the const keyword can have their own static properties and functions using the keyword static before var or function and can also can constructors and destructors see below . Static properties and functions are accessed see below using a different format than usual for objects and static functions cannot access the objects properties . the variable this is not defined inside of a static function . Accessing properties and methods Once you have an object you access methods and properties variables of the object using the - gt notation. Constructors and destructors Constructors are methods that are generally used to initialize the object s properties with values as the object is created. Declare a constructor function in an object by writing a function

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.