Differences between passing value assignment in php and referencing value assignment

Source: Internet
Author: User
Tags php session php template
Reference assignment: this means that the new variable simply references the original variable (in other words, "become its alias" or "point. Changing new variables will affect the original variables, and vice versa. Value assignment: When a value of an expression is assigned to a variable, the value of the original expression is assigned to the target variable. This means that, for example, changing the value of one variable when the value of one variable is assigned to another will not affect the value of another variable.

The code is as follows:


$ A = 123; $ a = 123;
$ B = $ a; $ B = & $;
$ A = 321; $ a = 321;
Echo "$ a, $ B"; // Display "321,123" Echo "$ a, $ B"; // Display "321,321"
?> ?>
Reference assignment: The new variable simply references the original variable. changing the new variable will affect the original variable's use of reference assignment. simply add an & symbol to the variable to be assigned (source variable)
Type magic PHP does not require (or do not support) explicit type definitions in variable definitions. variable types are determined by the context in which the variable is used. That is to say, if a string value is assigned to the variable var, var becomes a string. If another integer value is assigned to var, it becomes an integer.
Type forced conversion
The following mandatory conversions are allowed: (int), (integer)-converted to an integer (bool), (boolean)-converted to a boolean (float), (double), (real) -convert to float (string)-convert to string (array)-convert to array (object)-convert to object Settype () for type conversion
Settype ()
[Code]
$ Foo = "5bar"; // string
$ Bar = true; // boolean

Settype ($ foo, "integer"); // $ foo is now 5 (integer)
Settype ($ bar, "string"); // $ bar is now "1" (string)
?>


The scope of a variable is the context defined by the variable (that is, its effective range ). Most PHP variables have only one separate range. This separate range span also contains the files introduced by include and require.
Another important feature of static variable range is static variable ). Static variables only exist in local function domains, but their values are not lost when the program runs out of this scope.
The array in PHP is actually an ordered graph. A graph is a type that maps values to keys. This type has been optimized in many aspects, so it can be used as a real array, or a list (vector), a scattered list (an implementation of a graph), a dictionary, set, stack, queue, and more possibilities. Because another PHP array can be used as the value, and the tree can be easily simulated.
You can use the array () language structure to create an array. It accepts a certain number of key => value parameter pairs separated by commas.
Array (key => value ,...)
// The key can be integer or string.
// Value can be any value

The code is as follows:


// Create a simple array foreach ($ array as $ I => $ value ){
$ Array = array (1, 2, 3, 4, 5); unset ($ array [$ I]);
Print_r ($ array );}
Print_r ($ array );
// Add a unit (note that the new key name is 5, rather than the value 0 you may think)
$ Array [] = 6;
Print_r ($ array); // re-index:
$ Array = array_values ($ array );
$ Array [] = 7;
Print_r ($ array );
?>


The unset () function allows you to cancel the key name in an array. Note that the array will not rebuild the index.

The code is as follows:


$ A = array (1 => 'one', 2 => 'two', 3 => 'Three ');
Unset ($ a [2]);
/* Generates an array, defined
$ A = array (1 => 'one', 3 => 'Three ');
Instead
$ A = array (1 => 'one', 2 => 'Three ');
*/
$ B = array_values ($ );
// Now $ B is array (0 => 'one', 1 => 'Three ')
?>


Constructor
Void _ construct ([mixed $ args [, $...])
PHP 5 allows developers to define a method in a class as a constructor. Classes with constructors call this method each time an object is created, so it is very suitable for initialization before using the object.
Note: If the constructor is defined in the subclass, the constructor of its parent class will not be called secretly. To execute the constructor of the parent class, you must call parent ::__ construct () in the constructor of the subclass ().
Example #1 use the new standard constructor

The code is as follows:


Class BaseClass {
Function _ construct (){
Print "In BaseClass constructor \ n ";
}
}
Class SubClass extends BaseClass {
Function _ construct (){
Parent: :__ construct ();
Print "In SubClass constructor \ n ";
}
}
$ Obj = new BaseClass ();
$ Obj = new SubClass ();
?>


Fields in double quotation marks are interpreted by the compiler and then output as html code. The single quotes are output directly without explanation. $ Abc = 'My name is tom '; echo $ abc // The result is my name is tom; echo' $ ABC' // The result is $ abc; echo "$ abc" // The result is my name is tom


Access control controls access to properties or methods by adding the public, protected, or private keywords. Class members defined by public can be accessed anywhere. class members defined by protected can be accessed by subclass and parent classes of their classes (of course, the class where the member is located can also be accessed), while the class members defined by private can only be accessed by the class where the member is located.

The code is as follows:


Class MyClass
{
Public $ public = 'public ';
Protected $ protected = 'protected ';
Private $ private = 'private ';
Function printHello ()
{
Echo $ this-> public;
Echo $ this-> protected;
Echo $ this-> private;
}
}


Abstract Class PHP 5 introduces abstract classes and abstract methods. You cannot create an instance of a class that has been defined as abstract. Any class that contains at least one abstract method must also be abstract. Methods defined as abstract are just a signal for declaring methods, and they cannot be defined.
When inheriting from an abstract class, declarations of all abstract methods in the parent class must be defined by subclasses. In addition, these methods must use the same access attribute. For example, if a method is defined as protected, the execution function must be defined as protected or public.
The interface object interface allows you to create code for executing a method of a specified class, without having to explain how these methods are operated (processed. Interfaces are used to define the use of interface keywords. They are also used as a standard class, but there is no way to define their content. All methods in the interface must be declared as public, which is a feature of the interface. Implements is used to implement an interface. All methods in an interface must be implemented within a class. ignoring these methods will lead to a fatal error. If you want to use a comma to separate each interface, the class can implement multiple interfaces.
Both the overload method call and member access can be loaded through the _ call ,__ get and _ set methods. These methods will only be triggered when you try to access an object that does not include a member or method or an inherited object. Not all overload methods must be defined as static. you can use the _ isset () and _ unset () methods to reload the isset () and unset () functions one by one from PHP 5.1.0.
The PHP $ _ GET variable obtains the "value" from the form through the get method. When the "$ _ GET" variable is used, all the variable names and variable values are displayed in the URL address bar. Therefore, when the information you send contains a password or other sensitive information, you cannot use this method again.
The function of the PHP $ _ POST variable is to get the form variable sent by the method = "post" method.
Case

The code is as follows:




Cookies are usually used to verify or identify a user. A Cookie is a small file sent from a server to a user's computer. Each time, when the same computer requests a page through a browser, the previously stored cookie will also be sent to the server. You can use PHP to create and obtain the cookie value.

The code is as follows:


Setcookie ("user", "Alex Porter", time () + 3600);?>

Get cookie value // Print a cookie
Echo $ _ COOKIE ["user"];
// A way to view all cookies
Print_r ($ _ COOKIE );
?>


The PHP session variable is used to store the user's session information or change the user's session settings. The Session variable stores the information of a single user, which can be used by all pages.

The Mvc mode separates the application representation from the underlying application logic in three parts: Model View Controller
When the Zend_controllers route sends a user request, it automatically finds a user named nameController in the controller directory. php file. here, the name corresponds to the specified controller name. This indicates that the controller named news corresponds to a controller named newscontroller. php files
Smarty is a php template engine that allows you to easily separate application output and presentation logic from application logic.
ZEND configuration
1. create local parsing C: \ WINNT \ system32 \ drivers \ etchosts
127.0.0.1 phpweb20 127.0.0.1 phpmyadmin
2. httpd. conf D: \ AppServ \ Apache2.2 \ conf
(1) open the rewrite engine hpptd. conf (no # module can be opened) # LoadModule rewrite_module
Remove the previous #
(2) open the VM # Include conf/extra/httpd-vhosts.conf remove the front #
3. httpd-vhosts.conf

The code is as follows:



ServerName phpweb20
DocumentRoot "d: \ appserv \ www \ phpweb20 \ htdocs"

AllowOverride All
Options All

Php_value include_path ".; d: \ appserv \ www \ phpweb20 \ include; D: \ AppServ \ php5 \ ext"


4. Create. htaccess
5. modify php. ini
C: \ WINNT
Import
Php_pdo.dll
Php_pdo_mysql.dll

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.