Home  >  Article  >  Backend Development  >  [Nangikaze Sharing] A must-read for PHP development. This is how I program now_PHP tutorial

[Nangikaze Sharing] A must-read for PHP development. This is how I program now_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:13:31933browse

's code example, the function is to help users reset their passwords (the code is simply to explain the problem, please don't pay too much attention to some irrelevant details)

is to receive the user's request to reset the password and perform corresponding checks. For better reusability, I assigned the password reset operation to a new function separately. After changing the password, I called to send a notification email to the user.

 
<code class="plain"><code class="variable"><code class="plain"><code class="string"><code class="plain">
<code class="plain"><code class="string"><code class="plain">
<code class="plain"><code class="string"><code class="plain">
<code class="plain"><code class="string"><code class="plain"> 
<code class="plain"><code class="string"><code class="plain">
 <code class="variable"> <code class="plain">
<code class="variable"> <code class="plain">
 <code class="plain" false>
 <code class="plain" true>
 <code class="variable"> <code class="plain">
<code class="variable"> <code class="plain">
 <code class="plain" false>
 <code class="plain" true>
 <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
  <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain"> 

This function checks the user does not exist, the database is queried three times, which brings some additional overhead.

, it seems possible. But if there are certain functions that need to be called or later, and the user does not exist, an error may occur in the system.

into , and a little later, write the logic of into it as well. In this way, function calls are reduced, database queries become one time, and performance is improved. However, the functions of resetting passwords and sending emails will not be reusable, and violate the principle of , and the code complexity will also increase.

Function:

 <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
<code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
<code class="variable"> <code class="plain"><code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">

Function.

 
 
 
 

 
<code class="plain"><code class="variable"><code class="plain"><code class="string"><code class="plain">
<code class="plain"><code class="string"><code class="plain">
<code class="plain"><code class="string"><code class="plain">
<code class="plain"><code class="string"><code class="plain"> 
<code class="plain"><code class="string"><code class="plain">
 <code class="variable"> <code class="plain">
<code class="variable"> <code class="plain">
 <code class="plain" false>
 <code class="plain" true>
 <code class="variable"> <code class="plain">
<code class="variable"> <code class="plain">
 <code class="plain" false>
 <code class="plain" true>
 <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
<code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
<code class="variable"> <code class="plain"><code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain">
  <code class="variable"> <code class="plain">
 <code class="variable"> <code class="plain"> 

 
 

Nangikaze Koenko -- more serious PHP platform development

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/440370.htmlTechArticle code example, the function is to help users reset their passwords (the code is to simply explain the problem, please don’t pay too much attention to some irrelevant information) Details) is to receive the user's request to reset the password and respond accordingly...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn