Miguel Guirao wrote:

Hello list!!

my name is not 'list' but I'll let you off this time.


Can I have a variable that is static and global at the same time within a
function?

here is some [linux] command line output that took about 30 seconds to 
generate, it
answers your question. you'll have to work out the answer yourself by reading 
the
output - next time why not run the test code yourself (unlike most people you 
actually
wrote some code to test) ???

$> php -r '
$data = "";
function newdata() { static $data; global $data; if (empty($data)) { $data = 
"TEST"; } return $data; }
var_dump($data, newdata(), $data, newdata());
'
string(0) ""
string(4) "TEST"
string(4) "TEST"
string(4) "TEST"


$> php -r '
$data = "";
function newdata() { global $data; static $data; if (empty($data)) { $data = 
"TEST"; } return $data; }
var_dump($data, newdata(), $data, newdata());
'
string(0) ""
string(4) "TEST"
string(0) ""
string(4) "TEST"


$> php -r '
$data = "";
function newdata() { static global $data; if (!isset($data)) { $data = "TEST"; 
} return $data; }
var_dump($data, newdata(), $data, newdata());
'

Parse error: parse error, unexpected T_GLOBAL, expecting T_VARIABLE in Command 
line code on line 3


Let's say I have:

$data = "";

function newdata() {
  static global $data;
  $data [$i] = $newdatatobestored_inthearray;
}

Best Regards,

-----------------------
Miguel Guirao Aguilera
Logistica R8 TELCEL
Tel. (999) 960.7994







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to