Skip to main content
Code Review

Return to Answer

replaced http://il1.php.net with https://www.php.net
Source Link

Review for the PHP part:

  • What problem does your class solve? Are you not doing too many things in one class? If your goal is to handle incoming Ajax requests, then a different object should handle the response.

  • Class names should be in CamelCaps, i.e. AjaxCon.

  • If you need something in your constructor (data from POST, etc), just ask for it in the constructor:

     public function __construct(array $post) {
    
  • Don't try to sanitize the entire $_POST array at once, it never works. What are you sanitizing it for? Data that goes into the database should go through prepared statements prepared statements , data that gets outputted back to the page as HTML should be run through htmlspecialchars() before they are outputted to the page. Don't sanitize data until the moment you need it, otherwise you risk double sanitation problems (Tom & Jerry becomes Tom & Jerry which becomes Tom & Jerry, oops).

  • Don't output in your function. Always return. Output should be on a single place only, and that's at the very end of the run, where you need to return the response after all processing is done.

  • Don't use get_object_vars($this) for the purpose you are using it. Specify exactly what variables you are returning, it's more readable.

  • Don't use globals - If you need to pass a variable from the outside to an anonymous function, use use:

     function($email) use ($ajaxCon) {
    
  • DO NOT USE GLOBALS - Seriously, don't.

Review for the PHP part:

  • What problem does your class solve? Are you not doing too many things in one class? If your goal is to handle incoming Ajax requests, then a different object should handle the response.

  • Class names should be in CamelCaps, i.e. AjaxCon.

  • If you need something in your constructor (data from POST, etc), just ask for it in the constructor:

     public function __construct(array $post) {
    
  • Don't try to sanitize the entire $_POST array at once, it never works. What are you sanitizing it for? Data that goes into the database should go through prepared statements , data that gets outputted back to the page as HTML should be run through htmlspecialchars() before they are outputted to the page. Don't sanitize data until the moment you need it, otherwise you risk double sanitation problems (Tom & Jerry becomes Tom & Jerry which becomes Tom & Jerry, oops).

  • Don't output in your function. Always return. Output should be on a single place only, and that's at the very end of the run, where you need to return the response after all processing is done.

  • Don't use get_object_vars($this) for the purpose you are using it. Specify exactly what variables you are returning, it's more readable.

  • Don't use globals - If you need to pass a variable from the outside to an anonymous function, use use:

     function($email) use ($ajaxCon) {
    
  • DO NOT USE GLOBALS - Seriously, don't.

Review for the PHP part:

  • What problem does your class solve? Are you not doing too many things in one class? If your goal is to handle incoming Ajax requests, then a different object should handle the response.

  • Class names should be in CamelCaps, i.e. AjaxCon.

  • If you need something in your constructor (data from POST, etc), just ask for it in the constructor:

     public function __construct(array $post) {
    
  • Don't try to sanitize the entire $_POST array at once, it never works. What are you sanitizing it for? Data that goes into the database should go through prepared statements , data that gets outputted back to the page as HTML should be run through htmlspecialchars() before they are outputted to the page. Don't sanitize data until the moment you need it, otherwise you risk double sanitation problems (Tom & Jerry becomes Tom & Jerry which becomes Tom & Jerry, oops).

  • Don't output in your function. Always return. Output should be on a single place only, and that's at the very end of the run, where you need to return the response after all processing is done.

  • Don't use get_object_vars($this) for the purpose you are using it. Specify exactly what variables you are returning, it's more readable.

  • Don't use globals - If you need to pass a variable from the outside to an anonymous function, use use:

     function($email) use ($ajaxCon) {
    
  • DO NOT USE GLOBALS - Seriously, don't.

Source Link
Madara's Ghost
  • 4.8k
  • 25
  • 46

Review for the PHP part:

  • What problem does your class solve? Are you not doing too many things in one class? If your goal is to handle incoming Ajax requests, then a different object should handle the response.

  • Class names should be in CamelCaps, i.e. AjaxCon.

  • If you need something in your constructor (data from POST, etc), just ask for it in the constructor:

     public function __construct(array $post) {
    
  • Don't try to sanitize the entire $_POST array at once, it never works. What are you sanitizing it for? Data that goes into the database should go through prepared statements , data that gets outputted back to the page as HTML should be run through htmlspecialchars() before they are outputted to the page. Don't sanitize data until the moment you need it, otherwise you risk double sanitation problems (Tom & Jerry becomes Tom & Jerry which becomes Tom & Jerry, oops).

  • Don't output in your function. Always return. Output should be on a single place only, and that's at the very end of the run, where you need to return the response after all processing is done.

  • Don't use get_object_vars($this) for the purpose you are using it. Specify exactly what variables you are returning, it's more readable.

  • Don't use globals - If you need to pass a variable from the outside to an anonymous function, use use:

     function($email) use ($ajaxCon) {
    
  • DO NOT USE GLOBALS - Seriously, don't.

lang-php

AltStyle によって変換されたページ (->オリジナル) /