


The difference between PHP assignment by value and assignment by reference_PHP Tutorial
Assignment by value: When assigning the value of an expression to a variable, the value of the entire original expression is assigned to the target variable. This means that, for example, changing the value of one variable while the value of one variable is assigned to another variable will not affect the other variable.
$a=123; $a =123;
$b=$a; $b=&$a;
$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 using reference assignment, simply add an & symbol in front of the variable to be assigned (source variable)
Type trick PHP does not require (or does not support) explicit type definition in variable definition; variable type is determined by the context in which the variable is used. That is, if you assign a string value to the variable var, var becomes a string. If you assign an integer value to var, it becomes an integer.
Type cast
The allowed casts are: (int), (integer) - converted to integer (bool), (boolean) - converted to Boolean (float), (double), (real) - Convert to floating point type (string) - Convert to string (array) - Convert to array (object) - Convert to object Settype() for type conversion
Function Settype()
[code]
$foo = "5bar"; // string
$bar = true; // boolean
settype($foo, "integer"); // $foo is now 5 (integer)
settype($bar, "string"); // $bar is now "1" (string)
?>
Variable scope The scope of the variable is The context it defines (that is, its scope of effect). Most PHP variables have only a single scope. This single scope span also includes files introduced by include and require.
Static variable Another important feature of variable scope is static variable. Static variables only exist in the local function scope, but their values are not lost when program execution leaves this scope.
Array An array in PHP is actually an ordered graph. A graph 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 a list (vector), a hash table (an implementation of a graph), a dictionary, a set, a stack, a queue, and many more possibilities. Since you can use another PHP array as a value, you can also simulate a tree easily.
Define array() You can use the array() language structure to create a new array. It accepts a number of comma-separated key => value parameter pairs.
array( key => value , ... )
// key can be integer or string
// value can be any value
// 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 to unset keys in an array. Be aware that the array will not be reindexed.
$a = array( 1 => 'one ', 2 => 'two', 3 => 'three' );
unset( $a[2] );
/* will produce an array, defined as
$a = array ( 1=>'one', 3=>'three');
instead of
$a = array( 1 => 'one', 2 => 'three');
*/
$b = array_values($a);
// Now $b is array(0 => 'one', 1 =>'three')
?>
Constructor
void __construct ([ mixed $args [, $... ]] )
PHP 5 allows developers to define a method as a constructor in a class. Classes with a constructor will call this method every time an object is created, so it is very suitable for doing some initialization work before using the object.
Note: If a constructor is defined in a subclass, the constructor of its parent class will not be called implicitly. To execute the parent class's constructor, you need to call parent::__construct() in the child class's constructor.
Example#1 Using the new standard constructor
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 in double quotes will be interpreted by the compiler and then output as html code. The words inside the single quotes are not interpreted and are output directly. $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 Access control of properties or methods is achieved by adding the keywords public, protected or private in front. Class members defined by public can be accessed from anywhere; class members defined by protected can be accessed by subclasses and parent classes of the class in which they are located (of course, the class in which the member is located can also be accessed); and by private The defined class members can only be accessed by the class in which they are located.
class MyClass
{
public $ public = 'Public';
protected $protected = 'Protected';
private $private = 'Private';
function printHello()
{
echo $this->public;
echo $this->protected;
echo $this->private;
}
}
Abstract classes Abstract classes and abstractions were introduced in PHP 5 method. It is not allowed to 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 merely a signal for declaring methods and do not 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 be defined with the same access attributes. For example, if a method is defined as a protected type, the execution function must be defined as protected or public.
Interface Object interface allows you to create execution code for methods of a specified class without having to explain how these methods are operated (processed) . The interface is used to define the interface keyword, again as a standard class, but no methods have their contents defined. All methods in an interface must be declared public. This is a characteristic of the interface. implements (execution, implementation) In order to implement an interface, the implements operation is used. All methods in an interface must be implemented inside a class; omitting these will result in a fatal error. A class can implement multiple interfaces if desired by separating each interface with a comma.
Overloaded method calls 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 or inherited object that does not contain members or methods. Not all overloaded methods must be defined as static. Starting from PHP 5.1.0, you can also overload the isset() and unset() functions one by one through the __isset() and __unset() methods.
The PHP $_GET variable obtains the "value" from the form through the get method. When using the "$_GET" variable, all variable names and values will be displayed in the URL address bar; therefore, you can no longer use this method when the information you send contains passwords or other sensitive information.
The purpose of the PHP $_POST variable is to get the form variables sent by the method = "post" method.
Case
Cookies are usually used to authenticate or identify a user. A cookie is a small file sent to the user's computer through the server. Each time, when the same computer requests a page through the browser, the previously stored cookie is also sent to the server. You can use PHP to create and get cookie values.
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 purpose of PHP session variables is to store the user’s session information or change the user’s session settings. The Session variable stores information about a single user and can be used by all pages.
The Mvc pattern separates the presentation of the application from the underlying application logic into three Part: Model View Controller
When the Zend_controllers route sends a user request, it will automatically look for a file named nameController.php in the controller directory, where name corresponds to the specified controller name, which means that the name is The news controller corresponds to a file named newscontroller.php
Smarty is a template engine written in PHP, which allows you to easily separate application output and presentation logic from application logic
ZEND configuration
1 , create local parsing C:WINNTsystem32driversetchosts
127.0.0.1 phpweb20 127.0.0.1 phpmyadmin
2. httpd.conf D:AppServApache2.2conf
(1) Open the rewrite engine hpptd.conf (the one without # can Open module) #LoadModule rewrite_module
Remove the preceding #
(2) Open the virtual host #Include conf/extra/httpd-vhosts.conf Remove the preceding #
3. httpd-vhosts.conf
ServerName phpweb20
DocumentRoot "d:appservwwwphpweb20htdocs"
AllowOverride All
Options All
php_value include_path ".;d:appservwwwphpweb20include;D:AppServphp5ext"
4. Create .htaccess
5. Modify php.ini
C:WINNT
Import
php_pdo.dll
php_pdo_mysql.dll

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Created by Ripple, Ripple is used for cross-border payments, which are fast and low-cost and suitable for small transaction payments. After registering a wallet and exchange, purchase and storage can be made.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

Discussing the hierarchical architecture in back-end development. In back-end development, hierarchical architecture is a common design pattern, usually including controller, service and dao three layers...

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.
