PHP Global Variables Learning Note _php Tutorial

Source: Internet
Author: User
Tags http file upload http post traits
Today we refer to PHP's official PHP global variable Introduction to understand some of the PHP global variables use and some of their own thinking about it, now share out hope that the students can help.


First, the core points of thinking:

1. What global variables are out of date and how are they handled?
such as: unset ($GLOBALS, $_env, $HTTP _get_vars, $HTTP _post_vars, $HTTP _cookie_vars, $HTTP _server_vars, $HTTP _env_vars);
2. What global variables are not valid under the command line?
3. Htmlspecialchars () Usage, why use it?
4. $_request and $_get, $_post,$_cookie's connection and distinction?
5. Why did you upload the file but the $_files variable does not exist or is empty?
6. Scope of global variables?
7. I want to obtain the user's IP and browser user_agent information, how to fetch?
8. I do not use the browser, I am socket programming? How do I keep the session?
9. How do I obtain headers information?


PHP Nine global pre-defined arrays

Hyper global variable-a hyper-global variable is a built-in variable that is always available in all scopes
$GLOBALS-Referencing all variables available in the global scope
$_server-Server and execution Environment information
$_get-http GET Variable
$_post-http POST variables
$_files-http File Upload variables
$_request-http REQUEST Variable
$_session-session variable
$_env-Environment variables
$_cookie-http Cookies
$php _errormsg-a previous error message
$HTTP _raw_post_data-native POST data
$http _response_header-http Response Head
$ARGC-Number of arguments passed to the script
$ARGV-An array of arguments passed to the script

Ii. Major Issues
====================================

PHP Basic Article Summary topic:
1>. Var_dump (0== "ads"); What is the result of this statement? Why?
Answer: This statement results in true;
The string to the right of this expression is cast by default to int data 0, which is the same as the left data, so the output is true, and if it is "= = =", the output is false, because they are of different types and the values are not cast here.

Reviews: This is really hard to say, test it! Var_dump () Prints the result of an expression! The actual test is the expression operation.

2>: Can exceptions be cloned?
Answer: No.

3>. What are the features of traits in PHP?
A: Traits (horizontal reuse/multiple inheritance) is a set of methods that structure much like a class, but it cannot be instantiated, which allows developers to easily reuse methods in different classes;
The best application of traits is that the same functions can be shared among multiple classes;
Static variables can be referenced by trait methods, but cannot be defined by trait. However, trait can define static methods for the classes used;
If trait defines an attribute, the class will not be able to define properties of the same name, otherwise an error will be generated;

Summary: The question is good, the answer is also very good

=====================================

1. What are the Super global variables? Answer: Super Global variables: $GLOBALS, $_server, $_get, $_post, $_files, $_cookie, $_session, $_request, $_env

2, the browser to disable the cookie, $_session can still use it? A: I can't use it.
Comments: Wrong answer, can use! Apache has automatic functionality to put session_id on get parameters.

3. When are $php _errormsg available? A: No, this variable is only available within the scope of the error, and requires that the Track_errors configuration item be turned on (it is off by default).

Summary: Very positive, answer can be in the fullness a little better

========================================

There's a humane interview problem.
Write a 30 php string function.
Cases:
Trim () Remove spaces from a string
Chop () from right to left, delete the specified character, parameter RTrim (string,find);
RTrim () from right to left, delete the specified character, parameter RTrim (string,find);
Chr () returns the ASC2 code of the character
Var_dump () Prints a value, can be any form, and returns the value of the property
Print () prints an array or string
Print_r () simply prints the string and the number, and the array is displayed with the enclosed key and the list of merits
Chunk_split () splits a string into a series of smaller parts
Implode () combines array elements into a single string
Join () combines array elements into a single string
Explode () splitting a string into an array
MD5 () returns a MD5 value, irreversible
Strlen () Gets the length of a string
Str_replace replacing some characters in a string
Mb_substr MB Extended intercept string function, format: MB_SUBSTR (string,start_num,end_num, ' utf-8 ')
Str_split splits a string into an array by character spacing
Strpos Find and return the position of the first occurrence
STRTR convert a specific character in a string
substr to intercept a string
Substr_count count occurrences of a character segment in a string
Substr_replace to replace part of a character in a string
WordWrap function to wrap strings by a specified length
Addcslashes () adds a backslash before the specified character
Strtolower () Converts a string to lowercase
Strtoupper () Converts a string to uppercase
Strrev () Invert string
Strripos () find where the string last appears in another string (case insensitive)
Strrpos () find where the string last appears in another string (case sensitive)
STRSPN () returns the number of specific characters contained in the string
Ucwords () converts the first character of each word in a string to uppercase
Str_repeat () repeats a string for a specified number of times
...

=======================================

1. Must the namespace be the first statement of the program script?
Answer: Yes

2. How do I cancel a reference?
Answer: unset ();

3, if a class, at least one of its methods is declared abstract, then this class must be declared abstract class? When inheriting an abstract class, does the subclass have to define all the abstract methods in the parent class?
Answer: If there is an abstract method in a class, the class must be defined as an abstract class, and when inheriting an abstract class, the child class must define all the abstract methods in the parent class.

========================================

1. How to get the absolute path of the file
Use the Realpath () function to return the absolute path name. If it fails, it returns false, for example, the file does not exist.
Echo Realpath ("test.txt");
Output:
C:wwwtestwebtest.txt

How the 2.session works
The session is saved on the server, but it is stored as a cookie in the client's SessionID, and if cookies are disabled, they need to be implemented using the URL rewriting mechanism of the Get method or using the Post method to submit a hidden form.

Reviews: This is the principle, but generally the Web server will automatically complete this function, do not need to add in the program.

Is the function of the 3.public static declaration a static method?
public static declared functions are static methods that can be used directly in the class, class Name:: Method invocation of Function name not in the way of new declaration
Note: You cannot have dynamic content such as $this-> in a function
In general, content that requires frequent execution is declared with static

Summary: The working principle of the session is well organized, analysis is very thorough. Hope to be more positive, continue to work hard

http://www.bkjia.com/PHPjc/632673.html www.bkjia.com true http://www.bkjia.com/PHPjc/632673.html techarticle today we refer to PHP's official PHP global variable Introduction to understand some of the PHP global variables use and some of their own thinking about it, now share out hope that the students can help. A ...

  • Related Article

    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.