Publishing AJAX and PHP - part 12

Trong lớp học, bạn có thể thực hiện hai phương pháp đặc biệt gọi là các nhà xây dựng và hàm hủy. xây dựng này được gọi là __construct (), và được thực hiện tự động khi bạn tạo ra các trường hợp mới của một lớp. | Server-Side Techniques with PHP and MySQL In classes you can implement two special methods called the constructor and destructor. The constructor is called construct and is executed automatically when you create new instances of a class. The constructor is useful when you have code that initializes various class members because you can rely on it always executing as soon as a new object of the class is created. The destructor is named destruct and is called automatically when the object is destroyed. Destructors are very useful for doing housekeeping work. In most examples we will close the database connection in the destructor ensuring that we don t leave any database connections open consuming unnecessary resources. It is true that it may be a bit better for performance to create the database connection just before needing it instead of the class constructor and to close it right after using it instead of the class destructor. However we choose to use the constructor and destructor because we get cleaner code where we are less likely to cause errors by forgetting to close the connection for example. When referring to any class member you must specify the object it is a part of. If you want to access a local class member you must use the special this object that refers to the current class instance. The public interface of a class consists of its public members which are accessible from the outside and can be used by programs that create instances of the class. Class members can be public private or protected. Private members can be used only internally by the class and protected members can be used by derived classes. Separating the various layers of functionality of an application is important because it allows you to build flexible and extensible applications that can be easily updated when necessary. In Cristian Darie and Mihai Bucica s PHP e-commerce books you even learn how to use a templating engine called Smarty that allows you to further separate .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
94    767    36    01-05-2024
Đã 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.