Analyze the misunderstanding of single and double quotes in PHP and _php tips of double quotes

Source: Internet
Author: User
Tags php and

Many programmers think that in PHP, single and double quotes are the same, in fact, it depends on how to use, in some ways they are the same, but there are some aspects of them are very different, today's small series to tell you what the difference.

1, in general, the two are general. But if the double quotes are written inside the variable, the parse operation is performed, and the single quote does not parse, how does this say? Let's give an example.

Let's see it now!

2, the implementation of the efficiency is not the same, single quotes faster than the execution speed of double quotes, if it is the same large program, this aspect or should pay attention to optimization, after all, PHP belongs to the interpretation of the language. So if there's only a pure string inside, with a single quote (speed), there's something else inside (like a variable) that's more flexible with a double.

PHP double quotes small Hidden trouble

Many of the syntax features of PHP can give an attacker an opportunity, for example, PHP detects variables in double quotes.

Execute the following code:

function test ()
{
 echo "abc";
}
echo "${@test ()}";
 
or

 echo ${@phpinfo ()};

The principle is as follows:

$a = ' B ';
$b = ' a ';
 
echo $ $a; A

The above makes use of PHP variable variables, double quotes {} can parse the variable content characteristics within double quotes create a little trouble. Do you understand? These misunderstandings and small hidden trouble programmers should pay more attention in peacetime.

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.