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();


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

        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.


Re: How to solve invalid context for a Class __construct() 80 80

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 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.