How to determine PHP operator priority

Source: Internet
Author: User
Tags constant definition php operator

When learning PHP, you may encounter a PHP operator priority problem. Here we will introduce the solution to the PHP operator priority problem. Here we will share it with you. PHP supports an error control operator :@. Before placing the expression in a PHP expression, any error information that may be generated by the expression is ignored. If the track_errors feature is activated, any error messages generated by the expression are stored in the variable $ php_errormsg. This variable will be overwritten every time an error occurs, so if you want to use it, you should check it as soon as possible.

 
 
  1. <?php 
  2. $my_file=@file('non_existent_file')or  
  3. die("Failedopeningfile:errorwas'$php_errormsg'");  
  4. $value=@$cache[$key];  
  5. ?> 

Note: The @ operator is only valid for expressions. For beginners, a simple PHP operator priority rule is: if you can get a value from somewhere, you can add the @ operator before it. For example, you can place it before variables, functions, include () calls, constants, and so on. It cannot be placed before the definition of a function or class, nor can it be used for condition structures such as if and foreach. Execution OPERATOR: PHP supports an execution OPERATOR: backquotes (''). Note that this is not a single quotation mark! PHP will try to execute the content in the back quotes as a shell command and return its output information (for example, it can be assigned to a variable rather than simply discarded to the standard output ). The effect of using the unquoted operator "'" is the same as that of the shell_exec () function.

 
 
  1. <?php 
  2. $output=`ls-al`;  
  3. echo"<pre>$output</pre>";  
  4. ?> 

Note: The Ampersand operator is invalid when safe mode is activated or shell_exec () is disabled.

Plus or minus one operator:
+ + $ A add the value of $ a plus one, and then return $.
$ A ++ returns $ a after adding, and then adds the value of $.
-- Minus $ a before $ a minus one, and then returns $.
$ A -- returns $ a after subtraction, and then drops the value of $ a by one.

This is the same as the C language auto-increment and auto-subtraction. Let's take a simple example to learn more.

 
 
  1. <Html> 
  2. <Head> 
  3. <Title>Php constant definition -- A Tao's essay</Title> 
  4. </Head> 
  5. <Body> 
  6.  
  7. <?Php 
  8.  
  9. $A=3;
  10. $A= ++ $;
  11. Echo $ ."<Br>";
  12.  
  13. // The output value is 4.
  14.  
  15. $A=3;
  16. $A= $ A ++;
  17. Echo $;
  18.  
  19. // The output value is 3.
  20.  
  21. ?> 
  22.  
  23. </Body> 
  24.  
  25. </Html> 

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.