In addition to removing the ampersand, add these two lines to your script to make errors visible.
Code: Select all
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'On');
I expect this might make a "Notice: Undefined variable" error visible in your current code.
johniem wrote:because the $ftpstream and $login is outside the function..If i move them in then all is working fine..
If you declare a variable globally (outside a function), it is not automatically available within a function. Only superglobals ($_SERVER, $_POST, $GLOBALS, etc.) are automatically available to functions.
Option 1: Pass the variables as arguments.
Code: Select all
<?php
$a = 3;
$b = 4;
echo add($a, $b);
function add ($x, $y)
{
return $x + $y;
}
?>
Option 2: Allow the function to access the global variables by using the "global" statement.
Code: Select all
<?php
$a = 3;
$b = 4;
echo add();
function add ()
{
global $a, $b;
return $a + $b;
}
?>
Option 3: Use the superglobal array $GLOBALS.
Code: Select all
<?php
$a = 3;
$b = 4;
echo add();
function add ()
{
return $GLOBALS['a'] + $GLOBALS['b'];
}
?>
Option 4: Make a class so you can use $this.
Code: Select all
<?php
class C
{
var $a;
var $b;
function C ()
{
$this->a = 3;
$this->b = 4;
echo $this->add();
}
function add ()
{
return $this->a + $this->b;
}
}
new C;
?>
Edit: This post was recovered from search engine cache.