Why won't my PHP form check work?

When I try to submit a form to my site, I get the following error:

Fatal error: cannot access empty property in function / form _validation.php on line 15

Code to verify the form:

class Validation { var $success; var $post_data; var $errors; var $delimiter; function Validation($HTTP_POST_DATA) { $this->success = true; $this->errors = false; $this->$post_data = $HTTP_POST_DATA; $this->delimiter = "|"; while(list ($key, $val) = each ($this->$post_data)) { $this->{$key} = $val; } reset($this->$post_data); while(list ($key, $val) = each ($this->$post_data)) { if(method_exists($this, $key)) { $cmd = "\$this->".$key."();"; eval($cmd); } } } 

Code from the form page:

  include_once($APP_ROOT . "functions/index.php"); include_once($APP_ROOT . "functions/form_validation.php"); $CONTINUE = TRUE; $valid = new Validation($_POST); if($CONTINUE = $valid->success) { 

This code worked very well before we switched to PHP5. Any idea what I need to change to get it working again?

thanks

+4
source share
3 answers

Change this:

 $this->$post_data = $HTTP_POST_DATA; 

For this:

 $this->post_data = $HTTP_POST_DATA; 
+6
source

$this->$post_data should be $this->post_data

In the future, try looking at the line that the error message points to, because usually where the problem is!;)

+7
source

You can take care of the immediate problem by changing the line as follows:

 if(property_exists(this, $key)) $this->{$key} = $val; 

If you want to know exactly why this does not work, try printing a POST array in debug mode:

 function Validation($HTTP_POST_DATA) { echo '<pre>'. print_r($HTTP_POST_DATA, true). "</pre>\n"; ... rest of method ... 

Also change all instances of $this->$post_data to $this->post_data

+1
source

Source: https://habr.com/ru/post/1502892/


All Articles