TAILIEUCHUNG - Học php, mysql và javascript - p 13

Here I have also used an invaluable function called print_r. It asks PHP to display information about a variable in human readable form. The _r stands for “in human readable format.” In the case of the new object $object, it prints the following: User Object ( [name] = [password] = ) However, a browser compresses all the whitespace, so the output in a browser is slightly harder to read: User Object ( [name] = [password] = ) In any case, the output says that $object is a user-defined object that has the properties name and password. Creating an Object To create an object with a specified. | Here I have also used an invaluable function called print_r. It asks PHP to display information about a variable in human readable form. The _r stands for in human readable format. In the case of the new object object it prints the following User Object name password However a browser compresses all the whitespace so the output in a browser is slightly harder to read User Object name password In any case the output says that object is a user-defined object that has the properties name and password. Creating an Object To create an object with a specified class use the new keyword like this object new Class. Here are a couple of ways in which we could do this object new User temp new User name password On the first line we simply assign an object to the User class. In the second we pass parameters to the call. A class may require or prohibit arguments it may also allow arguments but not require them. Accessing Objects Let s add a few lines more to Example 5-10 and check the results. Example 5-11 extends the previous code by setting object properties and calling a method. Example 5-11. Creating and interacting with an object php object new User print_r object echo br object- name Joe object- password mypass print_r object echo br object- save_user class User public name password PHP Objects 101 function save_user echo Save User code goes here As you can see the syntax for accessing an object s property is object- property. Likewise you call a method like this object- method . You should note that the example property and method do not have signs in front of them. If you were to preface them with signs the code would not work as it would try to reference the value inside a variable. For example the expression object- property would attempt to look up the value assigned to a variable named property let s say that value is the string brown and then attempt to reference the property object- brown. If property is undefined an attempt to reference object- NULL would occur .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.