My Global variables are not working inside a function example. If i do the following
$a=10;
function myfunction() {
global $a;
echo ($a+5);
}
myfunction();
it returns nothing but it works this way around
function myfunction() {
//global $a;
$a=10;
echo ($a+5);
}
myfunction();
all code is on the same page
Here is the problem function and what i have to do to get it to work
function encryptAndEncode($strIn) {
//global $strEncryptionType
//,$strEncryptionPassword;
$strEncryptionType="AES";
$strEncryptionPassword="MyPassword";
//** AES encryption, CBC blocking with PKCS5 padding then HEX encoding - DEFAULT **
//** use initialization vector (IV) set from $strEncryptionPassword
$strIV = $strEncryptionPassword;
//** add PKCS5 padding to the text to be encypted
$strIn = addPKCS5Padding($strIn);
//** perform encryption with PHP's MCRYPT module
$strCrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $strEncryptionPassword, $strIn, MCRYPT_MODE_CBC, $strIV);
//** perform hex encoding and return
return "@" . strtoupper(bin2hex($strCrypt));
}
Found the issue :) Others may be having this problem. Though this is a separate page it is running inside wordpress and the code is direct on a page and not as a require or include.
To get around this I have to remove the vars that are set on the page and declare them in the the themes functions.php
It seems if you run globals inside anything to do with wordpress whether it is direct on the page or an include file, they all have to be pre declared in the themes function php. :)