To begin, here is the flow so you can understand the problem. I have four files, three of these are classes, I use two namespaces.
login.php is a form, when the form is submited, it comes back to itself and the code below is executed. The login.php calls the Zcrypt::Decrypt and Zcrypt::Encrypt with out issues. the Login::DoLogin(); is also called inside the login.php file.
In the Login.class.php (where DoLogin lives) file I create a new instance of DB, and can call Zcrypt::Decrypt with out error. In Login.class.php I call dbConnect();
In the DB.class.php (where dbConnect lives) file I am unable to call Zcrypt::Decrypt. It gives me a syntax error or that it can not find Zcrypt. I have tried Zcrypt::Decrypt([string]), \Zcrypt::Decrypt([string]), and even \Zcrypt::Decrypt([string]).
The question is, how come I can call Zcrypt in some classes but not others? Im I missing some code for this to work?
Here are my files
login.php:
require 'NS/helpdesk/Login.class.php';
require 'NS/helpdesk/Cryptv2.class.php';
require 'NS/helpdesk/DB.class.php';
use \net\[domain]\Zcrypt;
use \net\[domain]\helpdesk\Login;
#check to see if the form was submited and that the values are equal.
{
if (strlen($_POST['hvalue']) > 1 && $_SERVER['REMOTE_ADDR'] == Zcrypt::Decrypt($_POST['hvalue']) )
{
Login::DoLogin(); ###### This is where I call my static Login Class
}
else {
echo "bad form";
}
}
Login.class.php
namespace net\[domain]\helpdesk;
use \net\[domain]\helpdesk\DB;
use \net\[domain]\Zcrypt;
class Login
{
public function DoLogin()
{
#call to the database class to open the db
$DB = new DB();
$DB->dbConnect();
#This is to show I can call Zcrypt in this class (note, no \) and it works.
echo $dbPass = Zcrypt::Decrypt("[coded string]");
}
}
DB.class.php
namespace net\[domain]\helpdesk;
use \net\[domain]\Zcrypt;
class DB
{
public $dbHost = '[address]';
public $dbUser = '[un]';
public $dbPass = '[pw]';
######The two commented out lines below will not run. I get a syntax error
# public $dbPass = \Zcrypt::Decrypt("[strint]");
# public $dbPass = Zcrypt::Decrypt("[string]")
public $dbName = '[name]';
public $db;
public function __construct(){}
public function dbConnect()
{
[code]
}
}
Cryptv2.class.php
namespace net\[domain];
use Exception;
class Zcrypt
{
public static function Encrypt($i)
{
[code]
}
public static function Decrypt($i)
{
[code]
}
}
Thanks for your help.