PHP摘引的妙用
PHP引用的妙用
在:http://bardo.iteye.com/admin/blogs/848136?一文中我已详细讲了什么是引用。这里给大家讲一讲引用的妙用。
1、引用传参,这有两个作用,其一,使得外部变量与函数中变量同步更改。其二,实现无return却能返回多个参数。
2、对于大的数据结构,减少复制,从而减小内存消耗。
这是常用的用途。引用实际上,还有一些奇妙的用途不为人所知。目前刚发现了一个:
?
假如一个文件中有代码,如果我们在SHELL状态下使用:
$host=$_SERVER['HTTP_HOST'];
日志中就会出现notice信息。当然,你关闭了,并不代表它不产生。但为了能使网页与SHELL均能使用,我们还是要这样:
其一:
使用 error_reporting(245)将其关闭。
第二,直接阻止其出现:
$host=@$_SERVER['HTTP_HOST'];
第三、使用三元运算符。
$host=(isset($_SERVER['HTTP_HOST']))?$_SERVER['HTTP_HOST']:'';
?
但这均是常见的方法。
实际上,我们还有一种,让它不会出现notice信息的方法:
?
$host=& $_SERVER['HTTP_HOST'];
?
这样,我们就保证了,传参时绝不使用 isset, 或 @
?
只有在变量真正使用时,我们才用isset。这不仅是减少代码字符数,同时也是加快运行效率的手段。
?
好了,现在你不妨试一下,下面的代码,是否是这样运行的。
?
error_reporting(E_ALL); $ar=array(); $b=& $ar['test'] ; //你可以把前面的方法在这一行都试一下 $c='23' . $b .'31'; echo($c);
?
?当然,使用引用,最大的注意事项是,你要保证在使用中不能改变它。否则,引起原变量同步变更,你必须要是事先预知的。
?
所以,如果不能预知, 还是使用 @
?


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

AI Hentai Generator
Generate AI Hentai for free.

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



Recently, many Win11 users have reported that when shutting down, they are prompted that the taskhostwindow task host is executing the shutdown task. So what is going on? Users can enter the Desktop folder under the local registry editor, and then select AutoEndTasks in the right window to set it. Let this site carefully introduce to users the solution to this problem when shutting down. Windows 11 shutdown prompts that the taskhostwindow task host is executing the shutdown task. Solution 1. Use the key combination win key + r key, enter "regedit" and press Enter, as shown in the figure below. 2. Search for [HKEY

HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

The differences between master and host are: 1. Host can play the role of client or server, while master is the central server responsible for coordinating and managing other slave servers in a distributed system; 2. Host is an ordinary computer device, and master usually has Higher processing power and resources are used to process and distribute tasks, manage data, and maintain the stability of the entire system; 3. The host is a node in the network, and the master is the server that plays a core role in the distributed system.

The solutions to "no route to host" include checking the network connection, checking the IP address and port, checking the firewall configuration, checking the routing configuration, checking the network device configuration, checking the network service status, checking the network configuration and contacting the network administrator. Detailed introduction: 1. Check the network connection to ensure that the network connection between the client and the target host is normal. You can try to test network connectivity through the ping command or other network tools, and check whether hardware devices such as network cables, wireless networks, and routers are working properly. Make sure the network connection is stable, etc.

HTTP status code 403 means that the server rejected the client's request. The solution to http status code 403 is: 1. Check the authentication credentials. If the server requires authentication, ensure that the correct credentials are provided; 2. Check the IP address restrictions. If the server has restricted the IP address, ensure that the client's IP address is restricted. Whitelisted or not blacklisted; 3. Check the file permission settings. If the 403 status code is related to the permission settings of the file or directory, ensure that the client has sufficient permissions to access these files or directories, etc.

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

How to use NginxProxyManager to implement automatic jump from HTTP to HTTPS. With the development of the Internet, more and more websites are beginning to use the HTTPS protocol to encrypt data transmission to improve data security and user privacy protection. Since the HTTPS protocol requires the support of an SSL certificate, certain technical support is required when deploying the HTTPS protocol. Nginx is a powerful and commonly used HTTP server and reverse proxy server, and NginxProxy

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's
