I'm trying to make the transition to OOP PHP to help clean up the cluster of code I'm currently working with.
I'm using PHPass to hash passwords in my database but with this OOP approach, I can't get my head around how to call it in my class' login function.
As far as I can see, in all the places I've tried calling it, it's always declared before my class is initialised but it's still telling my it's undefined or a non-object.
db_config.php
...
require_once("PasswordHash.php"); // Location no.1 to try it
$password_hash = new PasswordHash(8, FALSE);
include_once("DB.php");
$db = new DB($db_connection);
...
init.php
//require_once("PasswordHash.php"); // Location no.2 to try it
//$password_hash = new PasswordHash(8, FALSE);
require_once("db_config.php")
..Other init stuff..
DB.php
class DB {
...
public function login() {
// global $password_hash; -> if uncommented I get an error saying it's a non-object
// Error here
$password_accepted = $password_hash->CheckPassword($p, $hp);
}
...
}
login.php
require_once("init.php");
$db->login();
I still haven't got my head fully around how class scope works in PHP so I have a feeling I'm missing something.