RE: [PHP] Wierd Variable Initialization

2008-09-25 Thread Ford, Mike
On 25 September 2008 03:45, VamVan advised:

 So guys,
 
 I found some thing strange that happened to me yesterday. Its small
but
 kinda freaked me out.
 
 So I have a tokenmap.php that I include include in different
configuration
 files. Some are classes and some are simple php files.
 
 So in my tokenmap.php I have declared an array as global.
 
 SO $GLOBAL['tokenmap'] = array()
 
 As a good programming practice what I did was:
 
 require_once('tokenmap.php');
 $tokenmap = array();
 $tokenmap = $GLOBAL['tokenmap'];
 print_r($tokenmap);
 
 The above displays empty array
 
 But when I do this , it works
 
 require_once('tokenmap.php');
 $tokenmap = $GLOBAL['tokenmap'];
 print_r($tokenmap);
 
 Its kind of wierd for me. I am trying to understand. Can some one shed
 some light on it for me.

Well, $GLOBALS['tokenmap'] is *exactly* *the* *same* *thing* as
$tokenmap when you're in the global scope (which I assume you are for
what you describe here to make sense).  So the assignment:

   $tokenmap = array();

is the same as:

   $GLOBALS['tokenmap'] = array();

And the assignment:

   $tokenmap = $GLOBALS['tokenmap'];

is essentially useless as it's the same as:

   $tokenmap = $tokenmap;

... or:

   $GLOBALS['tokenmap'] = $tokenmap;

... or even:

   $GLOBALS['tokenmap'] = $GLOBALS['tokenmap'];

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730




To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] Wierd Variable Initialization

2008-09-25 Thread VamVan
Interesting. Thank you

On Thu, Sep 25, 2008 at 2:01 AM, Ford, Mike [EMAIL PROTECTED] wrote:

 On 25 September 2008 03:45, VamVan advised:

  So guys,
 
  I found some thing strange that happened to me yesterday. Its small
 but
  kinda freaked me out.
 
  So I have a tokenmap.php that I include include in different
 configuration
  files. Some are classes and some are simple php files.
 
  So in my tokenmap.php I have declared an array as global.
 
  SO $GLOBAL['tokenmap'] = array()
 
  As a good programming practice what I did was:
 
  require_once('tokenmap.php');
  $tokenmap = array();
  $tokenmap = $GLOBAL['tokenmap'];
  print_r($tokenmap);
 
  The above displays empty array
 
  But when I do this , it works
 
  require_once('tokenmap.php');
  $tokenmap = $GLOBAL['tokenmap'];
  print_r($tokenmap);
 
  Its kind of wierd for me. I am trying to understand. Can some one shed
  some light on it for me.

 Well, $GLOBALS['tokenmap'] is *exactly* *the* *same* *thing* as
 $tokenmap when you're in the global scope (which I assume you are for
 what you describe here to make sense).  So the assignment:

   $tokenmap = array();

 is the same as:

   $GLOBALS['tokenmap'] = array();

 And the assignment:

   $tokenmap = $GLOBALS['tokenmap'];

 is essentially useless as it's the same as:

   $tokenmap = $tokenmap;

 ... or:

   $GLOBALS['tokenmap'] = $tokenmap;

 ... or even:

   $GLOBALS['tokenmap'] = $GLOBALS['tokenmap'];

 Cheers!

 Mike

  --
 Mike Ford,  Electronic Information Developer,
 C507, Leeds Metropolitan University, Civic Quarter Campus,
 Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
 Email: [EMAIL PROTECTED]
 Tel: +44 113 812 4730




 To view the terms under which this email is distributed, please go to
 http://disclaimer.leedsmet.ac.uk/email.htm

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




Re: [PHP] Wierd Variable Initialization

2008-09-24 Thread 惠新宸
Title: Laruence's Signature




register_global = on ?

VamVan wrote:

  So guys,

I found some thing strange that happened to me yesterday. Its small but
kinda freaked me out.

So I have a tokenmap.php that I include include in different configuration
files. Some are classes and some are simple php files.

So in my tokenmap.php I have declared an array as global.

SO $GLOBAL['tokenmap'] = array()

As a good programming practice what I did was:

require_once('tokenmap.php');
$tokenmap = array();
$tokenmap = $GLOBAL['tokenmap'];
print_r($tokenmap);

The above displays empty array

But when I do this , it works

require_once('tokenmap.php');
$tokenmap = $GLOBAL['tokenmap'];
print_r($tokenmap);

Its kind of wierd for me. I am trying to understand. Can some one shed some
light on it for me.

Thanks

  


-- 





惠
新宸 xinchen.hui |  SYS |  (+8610)82602112-7974 | :laruence






Re: [PHP] Wierd Variable Initialization

2008-09-24 Thread 惠新宸
Title: Laruence's Signature




register_global = on ?

VamVan wrote:

  So guys,

I found some thing strange that happened to me yesterday. Its small but
kinda freaked me out.

So I have a tokenmap.php that I include include in different configuration
files. Some are classes and some are simple php files.

So in my tokenmap.php I have declared an array as global.

SO $GLOBAL['tokenmap'] = array()

As a good programming practice what I did was:

require_once('tokenmap.php');
$tokenmap = array();
$tokenmap = $GLOBAL['tokenmap'];
print_r($tokenmap);

The above displays empty array

But when I do this , it works

require_once('tokenmap.php');
$tokenmap = $GLOBAL['tokenmap'];
print_r($tokenmap);

Its kind of wierd for me. I am trying to understand. Can some one shed some
light on it for me.

Thanks

  


-- 





惠
新宸 xinchen.hui |  SYS |  (+8610)82602112-7974 | :laruence






Re: [PHP] Wierd Variable Initialization

2008-09-24 Thread Chris

VamVan wrote:

So guys,

I found some thing strange that happened to me yesterday. Its small but
kinda freaked me out.

So I have a tokenmap.php that I include include in different configuration
files. Some are classes and some are simple php files.

So in my tokenmap.php I have declared an array as global.

SO $GLOBAL['tokenmap'] = array()


I assume you mean $GLOBALS ..



As a good programming practice what I did was:

require_once('tokenmap.php');
$tokenmap = array();
$tokenmap = $GLOBAL['tokenmap'];
print_r($tokenmap);

The above displays empty array


Why set it to an empty array first? You're just overriding it straight away.

It's pretty silly to do:

?php

$a = 1;
$b = 0;
$b = $a;

?


Add:

error_reporting(E_ALL);
ini_set('display_errors', true);

to the top of your script.

Any errors/notices/warnings?

--
Postgresql  php tutorials
http://www.designmagick.com/


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



Re: [PHP] Wierd Variable Initialization

2008-09-24 Thread Shelley
Yeah, use $GLOBALS[''], or
global $tokenmap;


2008/9/25 Chris [EMAIL PROTECTED]

 VamVan wrote:

 So guys,

 I found some thing strange that happened to me yesterday. Its small but
 kinda freaked me out.

 So I have a tokenmap.php that I include include in different configuration
 files. Some are classes and some are simple php files.

 So in my tokenmap.php I have declared an array as global.

 SO $GLOBAL['tokenmap'] = array()


 I assume you mean $GLOBALS ..


 As a good programming practice what I did was:

 require_once('tokenmap.php');
 $tokenmap = array();
 $tokenmap = $GLOBAL['tokenmap'];
 print_r($tokenmap);

 The above displays empty array


 Why set it to an empty array first? You're just overriding it straight
 away.

 It's pretty silly to do:

 ?php

 $a = 1;
 $b = 0;
 $b = $a;

 ?


 Add:

 error_reporting(E_ALL);
 ini_set('display_errors', true);

 to the top of your script.

 Any errors/notices/warnings?

 --
 Postgresql  php tutorials
 http://www.designmagick.com/


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




-- 
With best regards,
Shelley Shyan
http://phparch.cn