0

I'm new to Classes. For a project to improve my skills I'm stuck.

This project is a registration in which:

  1. form data is validated
  2. some variable from the form are encrypted
  3. some variables from the form are hashed

It is getting the Class for hashing to load and work that is a problem. Here is my code so far:

if (isset ($_POST['submit'])) {
  include ('include/Validate.php');
  
  $newUser = new Validate();

  if ($newUser->isValidated()){
    
    include ('include/Encrypt.php');
    $newEncrypt = new Encrypt();

    if($newEncrypt->isEncryptedOk()){

      include ('include/Hash.php');
      $newHash = new HashVariables();  //error occurs here

      if($newHash->isHashOk()){
        echo 'This is good';die();
      } else {
        echo 'This is bad';die();
      }
      
    } else {
      //NOT Encrypted ok, generate output
      $output = "    <div class=\"error\"><h1 id=\"encryptError\">Program halted.  Encryption failure.</h1></div>";
    }
  } else {
    .....what to do if $_POST not set

This is the error I get:

Call to private HashVariables::__construct() from invalid context in ..... and it pertains to Line 14 above.

Am I somehow breaking rules by having Classes nested in if's within if's?

I've googled the above error message and not found anything helpful.

In case this helps, here is the top of the HashVariables Class to the end of __construct():

class HashVariables {

  private $password;
  //private $passwordsalt_hash;
  private $salt;
  
  private function __construct(){
    
    $this->_errors = array();

    $this->password         = $this->verifyPassword($_POST['password1']);
    $this->salt             = $this->verifiySalt($_POST['salt']);  
  }

Thanks for taking time to read this.

D

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Triztian
0

I think it's the constructor's scope, you set it to private, so it cannot be called outside of the class definition, set the scope to public.

Regards, Triztian

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.