The difference between a PHP pass value assignment and a reference assignment

  • 2020-03-31 21:22:37
  • OfStack

Value assignment : when the value of an expression is assigned to a variable, the value of the entire original expression is assigned to the target variable. This means, for example, that when the value of one variable is assigned to another, changing the value of one variable will not affect the other variable.
 
<?php <?php 
$a=123; $a=123; 
$b=$a; $b=&$a; 
$a=321; $a=321; 
Echo " $a,$b " ;// According to" 321,123 "  Echo " $a,$b " ;// According to" 321,321 "  
?> ?> 
 Refer to the assignment  : the new variable simply references the original variable. Changing the new variable will affect the original variable using the reference assignment & Sign to the variable to be assigned (source variable)  
 A type of trick PHP  Explicit type definitions are not required (or supported) in variable definitions; The type of a variable is determined based on the context in which the variable is used. That is, if you assign a string value to a variable  var  . var  It becomes a string. If I assign another integer value to  var  Then it becomes an integer.  
 Type cast  
 The permitted casts are:  (int) . (integer) -  Convert to integer  (bool) . (boolean) -  Convert to Boolean  (float) . (double) . (real) -  Convert to floating point  (string) -  Convert to string  (array) -  Convert to array  (object) -  Convert to object  Settype() Type conversion  
 function Settype() 
[code] 
<?php 
$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 in which it is defined (that is, its effective scope). Most PHP variables have a single scope. This separate scope span also contains files that include and require imports.
Another important feature of static variable scope is static variable. Static variables exist only in the local function domain, but their values are not lost when program execution leaves this scope.
Arrays an array in PHP is actually an ordered graph. A diagram is a type that maps values to keys. This type is optimized in many ways, so it can be used as a real array, or as a list (vector), hash table (an implementation of a graph), dictionary, collection, stack, queue, and more. Because you can use another PHP array as a value, you can also easily simulate a tree.
Define array() you can use the array() language structure to create a new array. It accepts a certain number of comma-separated keys. Value parameter pair.
Array (key = > The value of... )
// key can be an integer or a string
// value can be any value
 
<?php //Now delete all the cells in it, but keep the structure of the array itself
//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 cell (note that the new key name is 5, not 0 as you might think)
$array[] = 6; 
print_r($array); //Reindex:
$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.
 
<?PHP 
$a = array( 1 => 'one', 2 => 'two', 3 => 'three' ); 
unset( $a[2] ); 
 
$b = array_values($a); 
// Now $b is array(0 => 'one', 1 =>'three') 
?> 

The constructor
Void arbitration ([mixed $args [, $...]])
PHP 5 allows line 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's a good idea to do some initialization before using the object.
Note: if a constructor is defined in a subclass, the constructor of its parent class is not implicitly called. To execute the constructor of the parent class, you need to call parent:: arbitration () in the constructor of the child class.
Example#1 USES the constructor of the new standard
 
<?php 
class BaseClass { 
function __construct() { 
print "In BaseClass constructorn"; 
} 
} 
class SubClass extends BaseClass { 
function __construct() { 
parent::__construct(); 
print "In SubClass constructorn"; 
} 
} 
$obj = new BaseClass(); 
$obj = new SubClass(); 
?> 

The fields inside the quotes are interpreted by the compiler and then output as HTML code. The inside of the single quotation mark is not interpreted and is printed directly. $ABC = 'my name is Tom'; Echo $ABC // 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 keyword public, protected, or private to the front. Class members defined by public can be accessed anywhere; Class members defined by protected can be accessed by subclasses and superclasses of the class they are in (and, of course, by the class they are in); A class member defined by private can only be accessed by its class.
 
<?php 
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. It is not allowed to create an instance of a class that is already defined as abstract. Any class that contains at least one abstract method must also be abstract. Methods that are defined as abstract are merely a signal to declare methods, not to define their implementation.
When inheriting from an abstract class, the declaration of tags for all abstract methods in the parent class must be defined by the subclass. In addition, these methods must define the same access properties. For example, if a method is defined as a protected type, the execution function must be defined as protected or public.
The interface object interface allows you to create execution code for methods of a specified class without specifying how those methods are manipulated. Interfaces are used to define the use of interface keywords, again as a standard class, but no methods have their contents defined. All methods in the interface must be declared public, which is a feature of the interface. Implements implements USES the implements operation to implement an interface. All methods in the interface must be implemented within a class; Neglecting these will result in a fatal error. If you desire to separate each interface by using a comma, a class can implement multiple interfaces.
Both overloaded method calls and member accesses can be loaded with the successive successive call, successive get, and successive set methods. These methods will only be triggered if you attempt to access an object or inheritance object that does not include members or methods. Not all overloaded methods must be defined as static. Starting with PHP 5.1.0, you can also override the isset() and unset() functions one by one by using the methods of s/s () and s/s ().
The PHP $_GET variable gets its "value" from the form through the get method. When the "$_GET" variable is used, all variable names and values are displayed in the URL bar. So, when you send a message that contains a password or other sensitive information, you can no longer use this method.
The PHP $_POST variable gets the form variable sent by the method = "post" method.
case
 
<form action="welcome.php" method="post"> 
Enter your name: 
<input type="text" name="name" /> 
Enter your age: 
<input type="text" name="age" /> 
<input type="submit" /> 
</form> 

Cookies are often used to authenticate or identify a user. A Cookie is a small file sent from a server to the user's computer. Each time the same computer requests a page through the browser, the stored cookie is sent to the server. You can use PHP to create and retrieve cookie values.
 
<?php 
setcookie("user", "Alex Porter", time()+3600); ?> 
<html> <body></body> </html> 
 To obtain cookie value <?php 
// Print a cookie 
echo $_COOKIE["user"]; 
// A way to view all cookies 
print_r($_COOKIE); 
?> 

The PHP session variable stores the user's session information or changes the user's session Settings. The Session variable stores information about a single user that can be used by all pages.
< ? PHP session_start (); ? > < Html> < Body> < / body> < / html>
The Mvc pattern separates the presentation of the application from the underlying application logic in three parts: the model view controller
When Zend_controllers routes a user request, it automatically looks for a file named namecontroller.php in the controller directory, where the name corresponds to the specified controller name, which means that the controller named news corresponds to a file named newscontroller.php
Smarty is a templating engine written in PHP that makes it easy to separate application output from presentation logic and application logic
ZEND configuration
1. Create a local parse 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 rewrite engine hpptd.conf (no # is open module) #LoadModule rewrite_module
Get rid of the # in front
(2) open the virtual host #Include conf/extra/httpd-vhosts.conf remove the previous #
3, the HTTPD - vhosts. Conf
 
<VirtualHost *:80> 
ServerName phpweb20 
DocumentRoot "d:appservwwwphpweb20htdocs" 
<Directory "d:appservwwwphpweb20htdocs"> 
AllowOverride All 
Options All 
</Directory> 
php_value include_path ".;d:appservwwwphpweb20include;D:AppServphp5ext" 
</VirtualHost> 

4. Create. Htaccess
5. Modify php.ini
C: \ WINNT
The import
Php_pdo. DLL
Php_pdo_mysql. DLL

Related articles: