Learning notes for PHP global variables

Source: Internet
Author: User
Tags abstract comments file upload http file upload http post http request rtrim traits


First, the core points of thinking:

1. What global variables are outdated and how to handle them?
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 and the difference?
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 get the user's IP and browser user_agent information, how to take?
8. I do not use the browser, I am the socket programming? How do I keep the session?
9. How do I get headers information?


PHP nine large global predefined arrays

Super global variable-Super global variable is a built-in variable that is always available in all scopes
$GLOBALS-refer to all variables available in the global scope
$_server-Server and execution Environment information
$_get-http get variable
$_post-http POST Variable
$_files-http File Upload Variable
$_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 Header
$ARGC-Number of arguments passed to the script
$ARGV-array of arguments passed to the script

Ii. Main issues
====================================

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

Comments: This is really difficult to say, test it! Var_dump () Print the result of an expression! The actual test is the expression operation.

2> can exceptions be cloned?
A: No, you can't.

3>. What are the features of traits in PHP?
A: Traits (horizontal reuse/multiple inheritance) is a group of methods that are much like a class, but it cannot be instantiated, allowing developers to reuse methods easily in different classes;
The best application of traits is that multiple classes can share the same function;
Static variables can be referenced by trait methods, but cannot be defined by trait. But trait can define static methods for the classes used;
If trait defines a property, that class will not be able to define an attribute of the same name, or an error will occur;

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

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

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

2, the browser to disable the cookie, $_session still can use it? A: It can't be used.
Comments: Wrong answer, can use! Apache has the automatic function of putting session_id in get parameters.

3, $php _errormsg is available at any time? A: No, this variable is only available in the scope where the error occurred and requires that the Track_errors configuration entry be turned on (the default is off).

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

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

There's a human interview problem.
Write 30 PHP String functions.
Cases:
Trim () Remove spaces from the 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 property of the value
Print () prints an array or string
Print_r () simply prints the strings and numbers, and the array is displayed in the enclosed key and worth list
Chunk_split () splits a string into a series of smaller parts
Implode () combines the array elements into a single string
Join () combines an array element into a string
Explode () split string into groups
MD5 () returns a MD5 value, not reversible
Strlen () Gets the length of a string
Str_replace some characters in a replacement string
Mb_substr MB Extended intercept string function, format: MB_SUBSTR (string,start_num,end_num, ' utf-8 ')
Str_split divides a string into an array by character spacing
Strpos finds and returns the location of the first occurrence
STRTR a specific character in a transform string
substr to intercept a string
Substr_count calculate the number of occurrences of a character segment in a string
Substr_replace to replace part of a character in a string
The WordWrap function handles the string in a specified length.
Addcslashes () Add a backslash before the specified character
Strtolower () Converts a string to lowercase
Strtoupper () Converts a string to uppercase
Strrev () Reverse string
Strripos () finds the last occurrence of a string in another string (not case sensitive)
Strrpos () finds the last occurrence of a string in another string (case sensitive)
STRSPN () returns the number of specific characters contained in a string
Ucwords () converts the first character of each word in the string to uppercase
Str_repeat () repeats the string by the specified number of times
...

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

1. Does the namespace have to be the first statement of the program script?
Answer: Yes

2, how to cancel the reference?
Answer: unset ();

3, if a class, which has at least one method is declared abstract, then this class must be declared as an 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 subclass must define all the abstract methods in the parent class.

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

1. How to get the absolute path of the file
Returns an absolute pathname using the Realpath () function. If it fails, it returns false, such as if the file does not exist.
Echo Realpath ("test.txt");
Output:
C:wwwtestwebtest.txt

The working principle of 2.session
The session is saved on the server, but is stored as a cookie in the client-side, and if the cookie is disabled, it needs to be implemented by using the URL rewrite mechanism of the Get method or by submitting the hidden form by using the Post method SessionID.

Comments: 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?
The function of the public static declaration is a static method, which can be applied directly to the class, class Name:: Method Invocation of Function name does not take the form of new declaration
Note: The function cannot have dynamic content such as $this->
In general, the content that needs to be performed frequently is static declaration

Summary: The working principle of the session is well organized and the analysis is thorough. Hope to be positive in the future and keep working hard.

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.