Weak PHP security question notes and php security question notes

Source: Internet
Author: User
Tags switch case

Weak PHP security question notes and php security question notes

I. type conversion problems

Intval (); var_dump (intval ('1asdfasd'); // 1 var_dump (intval ('awqw12'); // 0 var_dump (intval (array ())); // 0 var_dump (intval (array ('foo', 'val'); // 1 var_dump (intval (0x1A )); // 26 hexadecimal conversion var_dump (intval ('asdfqwer '); // 0

 

Intval if the conversion value is a string, no error is returned, but 0 is returned. If the conversion value is an array, there are two cases. If the conversion value is an empty array, 0 is returned, otherwise, 1 is returned.

Note: php uses a 32-Bit Memory to store an integer. A 32-bit memory can represent 4294967296 digits, with the characters-2147483647 to 2147483648;

 

Ii. Loose problem of built-in functions

 switch();      $i='3adcd';     switch($i){              case 1:                     echo 'i is 1';                     break;              case 2:                     echo 'i is 2';                     break;              case 3:                     echo 'i is 3';                     break;              default:                    echo 'i is default';                    break;     }

 

 

The above result enters switch case 3. Why? If switch is a case of the numeric type, switch converts the parameter to the int type, therefore, during the above execution, $ I is converted to type first, and the conversion result is 3...

 

 

 

  in_array();    $arr = [0,1,2,3,'test'];    var_dump(in_array('abd',$arr));    // true    var_dump(in_array('1bc',$arr));    // true

 

Why is the above execution result like this? I will use the query manual later. The official statement is that in_array adopts the loose comparison method by default, and the ratio is equal only, the above result is available only when the type of the value is the same, but the third parameter of the in_array function can be set to True, which is a rigorous comparison method.

 

The above are common areas of attention for development.

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.