Similar methods in php

Source: Internet
Author: User
Php has many optional syntaxes. For example, echo can use echo () and print () to output text. Their difference is that the print () function has a return value of 1, which indicates that the output is successful, 0 indicates that the output fails. If echo () is used, no return value is returned. What are the following statements for the optionality in logical expressions? Php $ p6or0; var_dump ($ p); $

Php has many optional syntaxes. For example, echo can use echo () and print () to output text. Their difference is that the print () function has a return value of 1, which indicates that the output is successful, 0 indicates that the output fails. If echo () is used, no return value is returned. What are the following statements for the optionality in logical expressions? Php $ p = 6 or 0; var_dump ($ p); $

Php has many optional syntaxes, such as echo.


Echo () and print () can both output text. The difference is that the print () function has a return value of 1 indicating that the output is successful, 0 indicates that the output fails, and 2 echo () there is no returned value.

Optionality in logical expressions

Let's look at the following statement.

 

The output result is:
Int (6) bool (true) int (6) bool (false)

The priority of = is higher than or, so the value is assigned first and then the or expression is calculated to get true. The priority of = is lower than or. Therefore, the value of the expression is calculated to true and then assigned to $ p, = Priority is higher than and. Therefore, $ p is assigned first and then the expression value is calculated. = Priority is lower than &. Therefore, the value of & Expression is calculated to false first, assign a value to $ p. The calculated values are true, as shown below:

 

The output result is: bool (true)

Use delimiters instead of string quotation marks

We know that the strings in php should be enclosed in single or double quotation marks, but escape characters must be used when the strings contain single or double quotation marks. Here, you can replace them with delimiters, as shown below:

$ Value = <
 
  

Code output:

This is the text aABC that will be encoded in the "" value variable. aABC. Here, aABC can be replaced by any string. The beginning and end of a single string must be the same. The last aABC must be written in the top lattice, and there must be no spaces in front.

Object-oriented

A class is a manifestation of abstract things. A class contains self-contained variables and functions. A class is like a blueprint. With this blueprint, we can build different individuals. Let's look at the following code:

class Box{    private $what_is_inside;        public function __construct($contents)    {        $this->$what_is_inside = $contents;    }        public function get_whats_inside()    {        return $this->$what_is_inside;    }}

The class definition starts with a class, and then specifies an arbitrary name, followed by curly brackets. Variables and methods are defined in the curly brackets. In this class, we define a variable and two methods. When this class is initialized, the constructor _ construct is first executed to assign values to the variables. Variable $ this indicates that the variable $ what_is_inside is the variable in the Box class, not the variable of the function in the class. $ This indicates a variable in this class, which can be called by any function in the class.

Attributes and Methods

For variables and functions in the process, we become attributes and methods in the process orientation, and define functions as methods in the class. The objects and standard interfaces provided by methods can be used by anyone. Private methods or attributes can only be used inside the class. common methods and attributes can be used both inside and outside the class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.