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 throughhtmlspecialchars()
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
becomesTom & Jerry
which becomesTom & 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 throughhtmlspecialchars()
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
becomesTom & Jerry
which becomesTom & 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 throughhtmlspecialchars()
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
becomesTom & Jerry
which becomesTom & 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 throughhtmlspecialchars()
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
becomesTom & Jerry
which becomesTom & 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.