I have 2 PHP files: fileA.php and fileB.php
In fileA.php, I have a constant and some variables. One such variable (we’ll call it “$test” is assigned a function call for a Boolean value (it’s the one with the argument of ‘register’).
In fileB.php, I have some echo statements that echo JavaScript (so in essence, fileB.php is actually more of a JavaScript file in PHP clothing). In this file, I try to use $test in the following way:
echo 'var test = " ' . $test . ' " ; ' ;
In doing this, I receive a “function not defined” message through the JavaScript console of Firebug. So thinking that this has something to do with the inclusion of fileA.php into fileB.php, I include fileA.php elsewhere in another different file to echo the contents of $test only to discover that it works fine in that other file… So it’s making me believe that this error has something to do with the way the JavaScript is being handled through the PHP echos.
What are some ways I can fix this?
The contents of fileA.php is below:
<?php
$siteurl = ($_SERVER["HTTP_HOST"] == 'localhost') ? 'http://localhost/websites/blah' : 'http://www.blah.com/user';
define('ABSPATH2', $siteurl);
include ABSPATH2 . '/includes/functions.php';
$test = blahFunction('register');
echo $test;
?>
“blahFunction()” is defined inside of the functions.php file…
The partial contents of fileB.php is below (the file is pretty large as it uses Adobe Spry):
<?php
include '../fileA.php';
echo 'var test = "'.$test.'";';
echo 'var dir = "'.ABSPATH2.'/stuff/morestuff/directory/c/";
window.onload = function(){setScreenClass();};
window.onresize = function(){setScreenClass();};
...
The error message about the undefined function is also saying that there’s a missing semi-colon from fileA.php but I’ve scoured that page for hours and can’t find anything wrong with it–hence my coming to the pros on here.
Any help on this would be appreciated as always. ![]()