Welcome Guest, Not a member yet? Register   Sign In
global problem in helper
#2

[eluser]tonanbarbarian[/eluser]
Unfortunately just declaring a variable in a PHP file, rather than inside a function, does not always make it global scope.
It depends on where the file is included from.

If you have your index.php file and it includes function.php then any variables set in function.php will be in the global scope.

However if index.php calls a function my_includes(), and that function includes the function.php file then the variables set in function.php will be in the my_includes variable scope, not the global scope.

That is what is happening here. Because a function, or class method, is being used to include the helper files the variables declared do not have global scope.

simply declare the variables as $GLOBALS['doviz_listesi'] and they will be declared as global, or make the fiest line of your file another global declaration like you have inside the function.

Code:
index.php
<?php
// do something
...
include('function.php');
?>

function.php
<?php
$foo = 'bar';
function something() {
  global $foo; // this will work
}
?>

Code:
index.php
<?php
// do something
...
my_includes();
...
function my_includes() {
  include('function.php');
}
...
?>

function.php
<?php
$foo = 'bar';
function something() {
  global $foo; // this will not work
}
?>

<?php
// do something
...
my_includes();
...
function my_includes() {
include('function.php');
}
...
?>

function.php
<?php
$GLOBALS['foo'] = 'bar';
function something() {
global $foo; // this will not work
}
?>[/code]


Messages In This Thread
global problem in helper - by El Forum - 12-13-2007, 09:29 AM
global problem in helper - by El Forum - 12-13-2007, 02:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB