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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.