Quá tải trong PHP cung cấp các phương tiện để tạo các thuộc tính và phương thức tự động. Các thực thể động này được xử lý thông qua các phương thức ma thuật mà người ta có thể thiết lập trong một lớp cho các loại hành động khác nhau. Show Các phương pháp quá tải được gọi khi tương tác với các thuộc tính hoặc phương thức chưa được khai báo hoặc không hiển thị trong phạm vi hiện tại. Phần còn lại của phần này sẽ sử dụng các thuật ngữ các thuộc tính không thể truy cập và các phương pháp không thể tiếp cận để chỉ sự kết hợp giữa tuyên bố và khả năng hiển thị này. Tất cả các phương pháp quá tải phải được định nghĩa là
Giải thích quá tải của PHP khác với hầu hết các ngôn ngữ hướng đối tượng. Quá tải theo truyền thống cung cấp khả năng có nhiều phương pháp cùng tên nhưng số lượng và loại đối số khác nhau.Quá tải tài sản __set(string public__set (Chuỗi public__get (chuỗi public__isset (chuỗi công khai__unset (chuỗi __set () được chạy khi viết dữ liệu thành các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. __get () được sử dụng để đọc dữ liệu từ các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại.isset() or empty() on inaccessible (protected or private) or non-existing properties. __isset () được kích hoạt bằng cách gọi isset () hoặc trống () trên các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại.unset() is used on inaccessible (protected or private) or non-existing properties. __unset () được gọi khi unset () được sử dụng trên các thuộc tính không thể tiếp cận (được bảo vệ hoặc riêng tư) hoặc không tồn tại. Đối số $ name là tên của tài sản đang được tương tác. Đối số giá trị $ của phương thức __set () Chỉ định giá trị thuộc tính $ name'ed phải được đặt thành.
Giải thích quá tải của PHP khác với hầu hết các ngôn ngữ hướng đối tượng. Quá tải theo truyền thống cung cấp khả năng có nhiều phương pháp cùng tên nhưng số lượng và loại đối số khác nhau. Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 295 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 296 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 297 Quá tải tài sản Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 29 public__set (Chuỗi $name, hỗn hợp $value): VOIDpublic__get (chuỗi public__isset (chuỗi công khai__unset (chuỗi __set () được chạy khi viết dữ liệu thành các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. __get () được sử dụng để đọc dữ liệu từ các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. __isset () được kích hoạt bằng cách gọi isset () hoặc trống () trên các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. Calling object method 'runTest' in object context Calling static method 'runTest' in static context2 Calling object method 'runTest' in object context Calling static method 'runTest' in static context3 Calling object method 'runTest' in object context Calling static method 'runTest' in static context4 Quá tải tài sản Calling object method 'runTest' in object context Calling static method 'runTest' in static context public__set (Chuỗi public__get (chuỗi Calling object method 'runTest' in object context Calling static method 'runTest' in static context5 Calling object method 'runTest' in object context Calling static method 'runTest' in static context6 Calling object method 'runTest' in object context Calling static method 'runTest' in static context7 Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 public__isset (chuỗi công khai__unset (chuỗi Calling object method 'runTest' in object context Calling static method 'runTest' in static context9
public 4__set () được chạy khi viết dữ liệu thành các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. ¶ __get () được sử dụng để đọc dữ liệu từ các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
public 8__isset () được kích hoạt bằng cách gọi isset () hoặc trống () trên các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. ¶ công khai__unset (chuỗi
Calling object method 'runTest' in object context Calling static method 'runTest' in static context8
public__isset (chuỗi công khai__unset (chuỗi
Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 __set () được chạy khi viết dữ liệu thành các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. ¶ __get () được sử dụng để đọc dữ liệu từ các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
__isset () được kích hoạt bằng cách gọi isset () hoặc trống () trên các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. ¶ __unset () được gọi khi unset () được sử dụng trên các thuộc tính không thể tiếp cận (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
Đối số $ name là tên của tài sản đang được tương tác. Đối số giá trị $ của phương thức __set () Chỉ định giá trị thuộc tính $ name'ed phải được đặt thành. ¶ công khai__unset (chuỗi
$value 7__set () được chạy khi viết dữ liệu thành các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. ¶ __get () được sử dụng để đọc dữ liệu từ các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 __isset () được kích hoạt bằng cách gọi isset () hoặc trống () trên các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. ¶ __unset () được gọi khi unset () được sử dụng trên các thuộc tính không thể tiếp cận (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 Đối số $ name là tên của tài sản đang được tương tác. Đối số giá trị $ của phương thức __set () Chỉ định giá trị thuộc tính $ name'ed phải được đặt thành. ¶ Thuộc tính quá tải chỉ hoạt động trong bối cảnh đối tượng. Các phương pháp ma thuật này sẽ không được kích hoạt trong bối cảnh tĩnh. Do đó, các phương pháp này không nên được tuyên bố tĩnh. Một cảnh báo được đưa ra nếu một trong những phương pháp quá tải ma thuật được khai báo
Giá trị trả về của __set () bị bỏ qua vì cách PHP xử lý toán tử gán. Tương tự, __get () không bao giờ được gọi khi chuỗi các bài tập với nhau như thế này: __unset () được gọi khi unset () được sử dụng trên các thuộc tính không thể tiếp cận (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
$name 1Đối số $ name là tên của tài sản đang được tương tác. Đối số giá trị $ của phương thức __set () Chỉ định giá trị thuộc tính $ name'ed phải được đặt thành. ¶ __get () được sử dụng để đọc dữ liệu từ các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 __isset () được kích hoạt bằng cách gọi isset () hoặc trống () trên các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. ¶ __unset () được gọi khi unset () được sử dụng trên các thuộc tính không thể tiếp cận (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
$name 9Đối số $ name là tên của tài sản đang được tương tác. Đối số giá trị $ của phương thức __set () Chỉ định giá trị thuộc tính $ name'ed phải được đặt thành. ¶ __get () được sử dụng để đọc dữ liệu từ các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 __isset () được kích hoạt bằng cách gọi isset () hoặc trống () trên các thuộc tính không thể truy cập (được bảo vệ hoặc riêng tư) hoặc không tồn tại. ¶ __unset () được gọi khi unset () được sử dụng trên các thuộc tính không thể tiếp cận (được bảo vệ hoặc riêng tư) hoặc không tồn tại.
Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 Nanhe Kumar ¶ ¶ 8 năm trước
$name 9Adeel Khan ¶ ¶ 15 năm trước
Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 Daevid tại Daevid Dot Com ¶ ¶ 13 năm trước
Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2900 Daniel Smith ¶ ¶ 11 năm trước Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2901 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2902 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2903 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2904 Dans at dansheps dot com ¶ ¶ 11 năm trước Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2905 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2906 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2907 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2908 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2909 Dans at dansheps dot com ¶ ¶ Marius ¶ Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2910 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2911 Calling object method 'runTest' in object context Calling static method 'runTest' in static context8 17 năm trước ¶ 13 năm trước Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2913 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2914 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2915 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2916 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2917 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2918 Daniel Smith ¶ ¶ 15 năm trước Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2919 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2920 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2921 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2922
Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2924 Daevid tại Daevid Dot Com ¶ Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2925 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2926 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2903 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2928 13 năm trước ¶ Daevid tại Daevid Dot Com ¶ Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2929 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2930 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2931 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2932 Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2933 13 năm trước ¶ Daniel Smith ¶ Setting 'a' to '1' Getting 'a' 1 Is 'a' set? bool(true) Unsetting 'a' Is 'a' set? bool(false) 1 Let's experiment with the private property named 'hidden': Privates are visible inside the class, so __get() not used... 2 Privates not visible outside of class, so __get() is used... Getting 'hidden' Notice: Undefined property via __get(): hidden in <file> on line 70 in <file> on line 2934 11 năm trướcQuá tải phương thức cho phép các phương thức khác nhau có cùng tên, nhưng các chữ ký khác nhau trong đó chữ ký có thể khác nhau theo số lượng tham số đầu vào hoặc loại tham số đầu vào hoặc hỗn hợp của cả hai.Quá tải phương pháp còn được gọi là đa hình thời gian biên dịch, đa hình tĩnh hoặc liên kết sớm trong Java.allows different methods to have the same name, but different signatures where the signature can differ by the number of input parameters or type of input parameters, or a mixture of both. Method overloading is also known as Compile-time Polymorphism, Static Polymorphism, or Early binding in Java.
Ví dụ, quá tải và ghi đè trong PHP với ví dụ là gì?Quá tải chức năng và ghi đè là tính năng OOPS trong PHP.Trong quá tải chức năng, nhiều hơn một hàm có thể có cùng một chữ ký phương thức nhưng số lượng đối số khác nhau.Nhưng trong trường hợp ghi đè chức năng, nhiều hơn một hàm sẽ có cùng chữ ký phương thức và số lượng đối số. |