Re: [PHP] $GLOBALS example script on php.net

2011-03-07 Thread FeIn
I am unable to provide a better definition that user defined variables.
User defined variables are variables that are declared by the user. User
here means the creator (or maintainer of the script).

So for:

?php
$a = 'A';
$b = 'B';
$c = 'C';

function globals() {
$globals = $GLOBALS;
print_r(Before...);
print_r($globals);

foreach (array(
'GLOBALS',
'_ENV',
'HTTP_ENV_VARS',
'_POST',
'HTTP_POST_VARS',
'_GET',
'HTTP_GET_VARS',
'_COOKIE',
'HTTP_COOKIE_VARS',
'_SERVER',
'HTTP_SERVER_VARS',
'_FILES',
'HTTP_POST_FILES',
'_REQUEST'
) as $var) {
unset($globals[$var]);
}
print(br /After...);
   print_r($globals);

return $globals;
}

globals();
?

You will get: Array( [a] = A [b] = B [c] = C ). $a, $b and $c are user
defined variables.


On Mon, Mar 7, 2011 at 7:54 AM, Ashim Kapoor ashimkap...@gmail.com wrote:



 Unsetting doesn't leave user defined variables. Unsetting simply destroys
 variables (or removes elements from an array, etc). There is nothing magic
 or hidden in that script. I think the note meant exactly what it said: after
 creating a local copy of the $GLOBALS array and removing super globals from
 it, all that's left in it are user defined variables. And that's exactly
 what gets returned from the function.



 This is a script vars.php


 ?php
 function globals() {
 $globals = $GLOBALS;
 print_r(Before...);
 print_r($globals);

 foreach (array(
 'GLOBALS',
 '_ENV',
 'HTTP_ENV_VARS',
 '_POST',
 'HTTP_POST_VARS',
 '_GET',
 'HTTP_GET_VARS',
 '_COOKIE',
 'HTTP_COOKIE_VARS',
 '_SERVER',
 'HTTP_SERVER_VARS',
 '_FILES',
 'HTTP_POST_FILES',
 '_REQUEST'
 ) as $var) {
 unset($globals[$var]);
 }
 print(br /After...);
print_r($globals);

 return $globals;
 }

 globals();
 ?

 I called http://localhost/vars.php?a=1

 I get : -

 Before...Array ( [GLOBALS] = Array *RECURSION* [_POST] = Array ( ) [_GET]
 = Array ( [a] = 1 ) [_COOKIE] = Array ( ) [_FILES] = Array ( ) )
 After...Array ( )

 ALL the variables are UNSET. I have a user defined $_GET[a] but that goes
 away too.

 One second, what do you mean by user defined variables? Maybe I am lost in
 comprehension


Re: [PHP] $GLOBALS example script on php.net

2011-03-07 Thread Ashim Kapoor
?php

$globalvar1=1;
$globalvar2=2;

function globals() {
$globals = $GLOBALS;
var_dump($GLOBALS);
print_r(br /Before...);
print_r($globals);
foreach (array(
'GLOBALS',
'_ENV',
'HTTP_ENV_VARS',
'_POST',
'HTTP_POST_VARS',
'_GET',
'HTTP_GET_VARS',
'_COOKIE',
'HTTP_COOKIE_VARS',
'_SERVER',
'HTTP_SERVER_VARS',
'_FILES',
'HTTP_POST_FILES',
'_REQUEST'
) as $var) {
unset($globals[$var]);
}
print(br /After...);
   print_r($globals);

return $globals;
}

globals();
?

array(7) { [GLOBALS]= array(7) { [GLOBALS]= *RECURSION* [_POST]=
array(0) { } [_GET]= array(0) { } [_COOKIE]= array(0) { } [_FILES]=
array(0) { } [globalvar1]= int(1) [globalvar2]= int(2) } [_POST]=
array(0) { } [_GET]= array(0) { } [_COOKIE]= array(0) { } [_FILES]=
array(0) { } [globalvar1]= int(1) [globalvar2]= int(2) }
Before...Array ( [GLOBALS] = Array *RECURSION* [_POST] = Array ( ) [_GET]
= Array ( ) [_COOKIE] = Array ( ) [_FILES] = Array ( ) [globalvar1] = 1
[globalvar2] = 2 )
After...Array ( [globalvar1] = 1 [globalvar2] = 2 )

Ok I see it now.

Thank you all,
Ashim.


Re: [PHP] $GLOBALS example script on php.net

2011-03-06 Thread Ashim Kapoor
It doesn't though, it creates a copy of the $_GLOBALS super global array,
removes entries that will have been set by the system (i.e. it leaves
user-defined variables) and then returns the ones that are left, so in that,
the user note is perfectly correct.

What has me puzzled is how unsetting LEAVES user defined variables ? Why
would that happen ?

The array in the function lists the common server-defined variables
 (HTTP_VARS, etc), which it unsets from the local copy of the super global
 array ($globals). Basically, it loops through the un-named array, and unsets
 that index from $globals.


Thank you,
Ashim


Re: [PHP] $GLOBALS example script on php.net

2011-03-06 Thread FeIn
Unsetting doesn't leave user defined variables. Unsetting simply destroys
variables (or removes elements from an array, etc). There is nothing magic
or hidden in that script. I think the note meant exactly what it said: after
creating a local copy of the $GLOBALS array and removing super globals from
it, all that's left in it are user defined variables. And that's exactly
what gets returned from the function.

On Sun, Mar 6, 2011 at 5:11 PM, Ashim Kapoor ashimkap...@gmail.com wrote:

 It doesn't though, it creates a copy of the $_GLOBALS super global array,
 removes entries that will have been set by the system (i.e. it leaves
 user-defined variables) and then returns the ones that are left, so in
 that,
 the user note is perfectly correct.

 What has me puzzled is how unsetting LEAVES user defined variables ? Why
 would that happen ?

 The array in the function lists the common server-defined variables
  (HTTP_VARS, etc), which it unsets from the local copy of the super global
  array ($globals). Basically, it loops through the un-named array, and
 unsets
  that index from $globals.
 

 Thank you,
 Ashim



Re: [PHP] $GLOBALS example script on php.net

2011-03-06 Thread Ashim Kapoor
Unsetting doesn't leave user defined variables. Unsetting simply destroys
 variables (or removes elements from an array, etc). There is nothing magic
 or hidden in that script. I think the note meant exactly what it said: after
 creating a local copy of the $GLOBALS array and removing super globals from
 it, all that's left in it are user defined variables. And that's exactly
 what gets returned from the function.



This is a script vars.php

?php
function globals() {
$globals = $GLOBALS;
print_r(Before...);
print_r($globals);
foreach (array(
'GLOBALS',
'_ENV',
'HTTP_ENV_VARS',
'_POST',
'HTTP_POST_VARS',
'_GET',
'HTTP_GET_VARS',
'_COOKIE',
'HTTP_COOKIE_VARS',
'_SERVER',
'HTTP_SERVER_VARS',
'_FILES',
'HTTP_POST_FILES',
'_REQUEST'
) as $var) {
unset($globals[$var]);
}
print(br /After...);
   print_r($globals);

return $globals;
}

globals();
?

I called http://localhost/vars.php?a=1

I get : -

Before...Array ( [GLOBALS] = Array *RECURSION* [_POST] = Array ( ) [_GET]
= Array ( [a] = 1 ) [_COOKIE] = Array ( ) [_FILES] = Array ( ) )
After...Array ( )

ALL the variables are UNSET. I have a user defined $_GET[a] but that goes
away too.

One second, what do you mean by user defined variables? Maybe I am lost in
comprehension


Re: [PHP] $GLOBALS example script on php.net

2011-03-05 Thread Richard Quadling
On 5 March 2011 05:44, Ashim Kapoor ashimkap...@gmail.com wrote:
 Dear all,

 I was reading this page
 http://php.net/manual/en/reserved.variables.globals.php and  I found the
 following script there : 


 Here's a function which returns an array of all user defined global
 variables:

 ?php
 function globals() {
    $globals = $GLOBALS;
    foreach (array(
        'GLOBALS',
        '_ENV',
        'HTTP_ENV_VARS',
        '_POST',
        'HTTP_POST_VARS',
        '_GET',
        'HTTP_GET_VARS',
        '_COOKIE',
        'HTTP_COOKIE_VARS',
        '_SERVER',
        'HTTP_SERVER_VARS',
        '_FILES',
        'HTTP_POST_FILES',
        '_REQUEST'
    ) as $var) {
        unset($globals[$var]);
    }

    return $globals;
 }
 ?

 I think that this script UNSETS each supergobal variable,but page says that
 it returns ALL user defined vars ? Can some one tell me how that is ?

 Thank you,
 Ashim


You are right. The user note is incorrect.

I'll remove it.



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] $GLOBALS example script on php.net

2011-03-05 Thread Ashim Kapoor

 I'll remove it.


 How does one remove user notes from  php.net ?

Thank you,
Ashim


Re: [PHP] $GLOBALS example script on php.net

2011-03-05 Thread David Hutto
On Sat, Mar 5, 2011 at 5:10 AM, Ashim Kapoor ashimkap...@gmail.com wrote:

 I'll remove it.


  How does one remove user notes from  php.net ?


I'd guest they had been granted access to the php.net page editor, but
I may be wrong. Not that that site hasn't been scraped by other sites
and added to their content, or been catalogued by google cache or
alexis, etc.


 Thank you,
 Ashim




-- 
According to theoretical physics, the division of spatial intervals as
the universe evolves gives rise to the fact that in another timeline,
your interdimensional counterpart received helpful advice from me...so
be eternally pleased for them.

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



Re: [PHP] $GLOBALS example script on php.net

2011-03-05 Thread Daniel Brown
On Sat, Mar 5, 2011 at 05:42, David Hutto smokefl...@gmail.com wrote:

 I'd guest they had been granted access to the php.net page editor, but
 I may be wrong. Not that that site hasn't been scraped by other sites
 and added to their content, or been catalogued by google cache or
 alexis, etc.

Richard is part of the documentation management team here in the
PHP project.  That's the only way you can modify or remove user notes.

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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



Re: [PHP] $GLOBALS example script on php.net

2011-03-05 Thread Ashim Kapoor
Dear Ashley,

I do follow the part when it creates a local copy of $GLOBALS.

When it unsets them, is there a subtlety of unset that it ONLY unsets system
defined entries? Could you please explain this ?

Thank you,
Ashim


[PHP] $GLOBALS example script on php.net

2011-03-04 Thread Ashim Kapoor
Dear all,

I was reading this page
http://php.net/manual/en/reserved.variables.globals.php and  I found the
following script there : 


Here's a function which returns an array of all user defined global
variables:

?php
function globals() {
$globals = $GLOBALS;
foreach (array(
'GLOBALS',
'_ENV',
'HTTP_ENV_VARS',
'_POST',
'HTTP_POST_VARS',
'_GET',
'HTTP_GET_VARS',
'_COOKIE',
'HTTP_COOKIE_VARS',
'_SERVER',
'HTTP_SERVER_VARS',
'_FILES',
'HTTP_POST_FILES',
'_REQUEST'
) as $var) {
unset($globals[$var]);
}

return $globals;
}
?

I think that this script UNSETS each supergobal variable,but page says that
it returns ALL user defined vars ? Can some one tell me how that is ?

Thank you,
Ashim


[PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Alice Wei

Hi, 

I have a snippet of code as shown in the following:

$message2=47406|Detroit;
$stringChunk2= explode(|, $message2);

 if ($message2!=) {
   $count_chunk2= count($stringChunk2);
   $count_chunk_2= $count_chunk2-1;
}

   for ($j=0; $j$count_chunk2; $j++) {

  $string3= $stringChunk2[$j];   
  if ($j $count_chunk_2) {
 $string2=  OR ;
 $string3=$string3.$string2;
   }
 else {
 //Don't do anything
   }
   echo $string3;
  }

The code itself works, but I would like to reuse $string3 variable somewhere 
else where I can build SQL statements from it. 
I tried using 

global $string3; 
echo $string3;

after the final curly brace, but I only get Detroit and not 47406 OR Detroit. 
Can anyone please suggest me what I should be using here?

Thanks for your help.

Alice

_
All-in-one security and maintenance for your PC.  Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail

Re: [PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Bastien Koert
[snip]
[/snip]

Alice,

The big problem here is that you are resetting the $string3 variable in the
loop

  for ($j=0; $j$count_chunk2; $j++) {

 $string3= $stringChunk2[$j];//  -- resetting
the value
 if ($j $count_chunk_2) {
$string2=  OR ;
$string3=$string3.$string2;
  }
else {
//Don't do anything
  }
  echo $string3;
 }


I am not sure of your goal since you have not stated it, but it certainly
should be easier to just replace the PIPE  with the OR

$message = str_replace(|,  OR , $message);



-- 

Bastien

Cat, the other other white meat


RE: [PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Alice Wei

Hi, 


  Sorry, I cannot use that because I am supposed to turn the string into 
something that looks like regions.name LIKE '%47406' OR regions.name LIKE 
'%Detroit', which I had to fix $string3 variable to   

  $string3=regions.name LIKE '% . $stringChunk2[$j] . ';

  The goal is that the $message variable would be only a $_POST['message'] 
variable so that the where clause can be generated dynamically. 
  The code I have above is part of my where clause in the full SQL statement I 
intend to
construct, which means I have to reuse this $string3 variable somewhere
else.
  
This is what my global declaration looks like: 

  if ($j $count_chunk_2) {

 $string2=  OR ;
 $string3=$string3.$string2;
 global $string3;
   }
 else {
 //Don't do anything
   }
   echo $string3;
  }
echo $string3;

   The last $string3 echo only gives me regions.name
LIKE '%Detroit' according to the current construct and not regions.name
LIKE '%47406' OR regions.name LIKE '%Detroit'. Is there something else I should 
do to have it give me the same output as the echo $string3 as I have had after 
the second to last curly brace? 

Thanks again for your help.

Alice


 Date: Thu, 6 Nov 2008 10:22:44 -0500
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 CC: php-general@lists.php.net
 Subject: Re: [PHP] Globals or Super Global Variables To Be Reused from For 
 Loops
 
 [snip]
 [/snip]
 
 Alice,
 
 The big problem here is that you are resetting the $string3 variable in the
 loop
 
   for ($j=0; $j$count_chunk2; $j++) {
 
  $string3= $stringChunk2[$j];//  -- resetting
 the value
  if ($j $count_chunk_2) {
 $string2=  OR ;
 $string3=$string3.$string2;
   }
 else {
 //Don't do anything
   }
   echo $string3;
  }
 
 
 I am not sure of your goal since you have not stated it, but it certainly
 should be easier to just replace the PIPE  with the OR
 
 $message = str_replace(|,  OR , $message);
 
 
 
 -- 
 
 Bastien
 
 Cat, the other other white meat

_
Express yourself with gadgets on Windows Live Spaces
http://discoverspaces.live.com?source=hmtag1loc=us

Re: [PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Jim Lucas
Alice Wei wrote:
 Hi, 
 
 
   Sorry, I cannot use that because I am supposed to turn the string into 
 something that looks like

Sounds like we are doing someones school work again.

 regions.name LIKE '%47406' OR regions.name LIKE '%Detroit', which I had to 
 fix $string3 variable to   
 
   $string3=regions.name LIKE '% . $stringChunk2[$j] . ';
 
   The goal is that the $message variable would be only a $_POST['message'] 
 variable so that the where clause can be generated dynamically. 
   The code I have above is part of my where clause in the full SQL statement 
 I intend to
 construct, which means I have to reuse this $string3 variable somewhere
 else.
   
 This is what my global declaration looks like: 
 
   if ($j $count_chunk_2) {
 
  $string2=  OR ;
  $string3=$string3.$string2;
  global $string3;
}
  else {
  //Don't do anything
}
echo $string3;
   }
 echo $string3;

against my better judgment, I believe this is what you are looking for.

# Get your starting string
$pieces = 47406|Detroit;

# Break it into the parts you are looking to use
$parts  = explode(|, $pieces);

# Empty temporary array
$tmpHolder = array();

# Loop through parts list
foreach ( $parts AS $part ) {

# Create a single statement and stuff it in your tmp array
$tmpHolder[] = regions.name LIKE '%{$part}';
}

# Join all the parts together, placing an OR between each element.
$string3 = join(' OR ', $tmpHolder);


 
The last $string3 echo only gives me regions.name
 LIKE '%Detroit' according to the current construct and not regions.name
 LIKE '%47406' OR regions.name LIKE '%Detroit'. Is there something else I 
 should do to have it give me the same output as the echo $string3 as I have 
 had after the second to last curly brace? 
 
 Thanks again for your help.
 
 Alice
 
 
 Date: Thu, 6 Nov 2008 10:22:44 -0500
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 CC: php-general@lists.php.net
 Subject: Re: [PHP] Globals or Super Global Variables To Be Reused from For 
 Loops

 [snip]
 [/snip]

 Alice,

 The big problem here is that you are resetting the $string3 variable in the
 loop

   for ($j=0; $j$count_chunk2; $j++) {

  $string3= $stringChunk2[$j];//  -- resetting
 the value
  if ($j $count_chunk_2) {
 $string2=  OR ;
 $string3=$string3.$string2;
   }
 else {
 //Don't do anything
   }
   echo $string3;
  }


 I am not sure of your goal since you have not stated it, but it certainly
 should be easier to just replace the PIPE  with the OR

 $message = str_replace(|,  OR , $message);



 -- 

 Bastien

 Cat, the other other white meat
 
 _
 Express yourself with gadgets on Windows Live Spaces
 http://discoverspaces.live.com?source=hmtag1loc=us


-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare


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



RE: [PHP] Globals or Super Global Variables To Be Reused from For Loops

2008-11-06 Thread Alice Wei

Hi, 

  Thanks for your tip, and I am surprised that this could be done so easily. 

Alice

 Date: Thu, 6 Nov 2008 08:11:48 -0800
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED]; php-general@lists.php.net
 Subject: Re: [PHP] Globals or Super Global Variables To Be Reused from For 
 Loops
 
 Alice Wei wrote:
  Hi, 
  
  
Sorry, I cannot use that because I am supposed to turn the string into 
  something that looks like
 
 Sounds like we are doing someones school work again.
 
  regions.name LIKE '%47406' OR regions.name LIKE '%Detroit', which I had to 
  fix $string3 variable to   
  
$string3=regions.name LIKE '% . $stringChunk2[$j] . ';
  
The goal is that the $message variable would be only a $_POST['message'] 
  variable so that the where clause can be generated dynamically. 
The code I have above is part of my where clause in the full SQL 
  statement I intend to
  construct, which means I have to reuse this $string3 variable somewhere
  else.

  This is what my global declaration looks like: 
  
if ($j $count_chunk_2) {
  
   $string2=  OR ;
   $string3=$string3.$string2;
   global $string3;
 }
   else {
   //Don't do anything
 }
 echo $string3;
}
  echo $string3;
 
 against my better judgment, I believe this is what you are looking for.
 
 # Get your starting string
 $pieces = 47406|Detroit;
 
 # Break it into the parts you are looking to use
 $parts  = explode(|, $pieces);
 
 # Empty temporary array
 $tmpHolder = array();
 
 # Loop through parts list
 foreach ( $parts AS $part ) {
 
   # Create a single statement and stuff it in your tmp array
   $tmpHolder[] = regions.name LIKE '%{$part}';
 }
 
 # Join all the parts together, placing an OR between each element.
 $string3 = join(' OR ', $tmpHolder);
 
 
  
 The last $string3 echo only gives me regions.name
  LIKE '%Detroit' according to the current construct and not regions.name
  LIKE '%47406' OR regions.name LIKE '%Detroit'. Is there something else I 
  should do to have it give me the same output as the echo $string3 as I have 
  had after the second to last curly brace? 
  
  Thanks again for your help.
  
  Alice
  
  
  Date: Thu, 6 Nov 2008 10:22:44 -0500
  From: [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  CC: php-general@lists.php.net
  Subject: Re: [PHP] Globals or Super Global Variables To Be Reused from For 
  Loops
 
  [snip]
  [/snip]
 
  Alice,
 
  The big problem here is that you are resetting the $string3 variable in the
  loop
 
for ($j=0; $j$count_chunk2; $j++) {
 
   $string3= $stringChunk2[$j];//  -- 
  resetting
  the value
   if ($j $count_chunk_2) {
  $string2=  OR ;
  $string3=$string3.$string2;
}
  else {
  //Don't do anything
}
echo $string3;
   }
 
 
  I am not sure of your goal since you have not stated it, but it certainly
  should be easier to just replace the PIPE  with the OR
 
  $message = str_replace(|,  OR , $message);
 
 
 
  -- 
 
  Bastien
 
  Cat, the other other white meat
  
  _
  Express yourself with gadgets on Windows Live Spaces
  http://discoverspaces.live.com?source=hmtag1loc=us
 
 
 -- 
 Jim Lucas
 
Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them.
 
 Twelfth Night, Act II, Scene V
 by William Shakespeare
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

_
Express yourself with gadgets on Windows Live Spaces
http://discoverspaces.live.com?source=hmtag1loc=us

[PHP] globals, simpletest and php from command line

2006-08-30 Thread blackwater dev

I have a php app that runs on php4.  I am writing some unit tests now using
SimpleTest but some of the libraries that I have to pull in for testing are
failing.  For example, my db library sets some params:

$dname=mydatabase;
$usr=me;
..etc

I then have some mysql functions that connect using

function con(){
 global $dname;
 ..etc.

}

When this is all run from the browser, things are fine but via simpletest
and command line, the globals are lost.  Is this just a problem with the
command line or with simpletest?

Thanks.


Re: [PHP] $GLOBALS, any probolems?

2005-02-10 Thread Richard Lynch
Bruno B B Magalhães wrote:
 is there any problems using $GLOBALS superglobal to carry all my global
 classes instances?

 For example:
 $GLOBALS['myclass'] = new myclass();

This is exactly the same as:
$myclass = new myclass();
as far as I've ever been able to tell, except that $GLOBALS is a
super-global, so it will work inside a function as well as outside.

For a brief period, it seemed like people were hot on using that instead
of 'global' in a function, so they didn't have to understand scoping.  Or
maybe it was the guys tired of trying to explain scoping to newbies who
were hot on it. :-^

Seems to me, you'd be better off understanding scoping rules and using
'global' so if you ever want to use another language, you'll have the good
programming habits, knowledge and skills you'll need.

But that's just my personal opinion.  Somebody gonna post and disagree
with me, almost for sure. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] $GLOBALS, any probolems?

2005-02-09 Thread Bruno B B Magalhães
Hi guys,
is there any problems using $GLOBALS superglobal to carry all my global 
classes instances?

For example:
$GLOBALS['myclass'] = new myclass();
Regards,
Bruno B B Magalhaes
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] globals

2004-03-31 Thread Daniel Bahena
is it too bad to have the globals = on in /etc/php.ini ?

Best wishes

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



Re: [PHP] globals

2004-03-31 Thread Robert Cummings
On Tue, 2004-03-30 at 20:31, Daniel Bahena wrote:
 is it too bad to have the globals = on in /etc/php.ini ?

It is strongly advised to have this set to off for security and
maintainability reasons.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



[PHP] Globals Variable question

2004-03-03 Thread Terence
Hi All,

Can someone tell me which is better, or if there's a reason I should use one
and not the other (since both seem to work), and if this is the
correct way to access script variables inside functions (and classes):

Example 1

$GLOBALS['db_name']=website;
function QueryDB() {
 echo $GLOBALS['var'];
}
QueryDB();

Example 2

$db_name=website;
function QueryDB() {
 echo $GLOBALS['var'];
}
QueryDB();


Many thanks

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



[PHP] Globals problem - $_REQUEST good solution?

2004-01-12 Thread Ryan A
Hi,
I am getting some variable from another program an the main problem is its
coming mixed...
eg:
some get and some post

So far I have coded this with register globals on because I didnt know which
way it was coming..
now i want to do it with globals off...

After going through the manual trying to find an answer I came accross
$_REQUEST, is this a good
solution? because I have never used this before or is this as bad as having
globals on?

Thanks,
-Ryan

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



Re: [PHP] Globals problem - $_REQUEST good solution?

2004-01-12 Thread CPT John W. Holmes
From: Ryan A [EMAIL PROTECTED]

 After going through the manual trying to find an answer I came accross
 $_REQUEST, is this a good
 solution? because I have never used this before or is this as bad as
having
 globals on?

The only simularity it has to register_globals ON is that you don't know
what method provided the value. It could be POST, GET, or COOKIE.

But... if you're validating the data properly anyhow, it really shouldn't
matter where it's coming from. I use $_REQUEST for everything, that way I
can change the method of my forms if I need to without affecting my code (or
the user can).

---John Holmes...

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



Re: [PHP] Globals problem - $_REQUEST good solution?

2004-01-12 Thread Ryan A
Cool.
Thanks John.

-Ryan

 The only simularity it has to register_globals ON is that you
 don't know
 what method provided the value. It could be POST, GET, or COOKIE.
 
 But... if you're
 validating the data properly anyhow, it really
 shouldn't
 matter where it's coming from. I use $_REQUEST for everything,
 that way I
 can change the method of my forms if I need to without affecting my code
 (or
 the user can).
 
 ---John Holmes...

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



[PHP] globals?

2004-01-06 Thread Bryan Koschmann - GKT
Hi,

I was just curious, how much longer are globals going to be supported? I
had heard awhile back that they wouldn't be around for too long.

Thanks,

Bryan

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



[PHP] $GLOBALS containing itself!!!

2003-12-15 Thread Gerard Samuel
Just curious about something I came across.
I was looking at the $GLOBAL array, to see what my script was leaving behind.
$GLOBALS contains a reference to itself.
Even though its a reference, whats the sense with that??
Once its global, why should it have to call on itself?
Im currently running php 4.3.4 on FreeBSD 4.9

Thanks

A script to try out -
?php

header('content-type: text/plain');

var_dump(isset($GLOBALS['GLOBALS']['GLOBALS']));  // returns true

// Prints out the $GLOBALS array
// including one reference to itself
// then starts another but quits with *RECURSION*
var_dump($GLOBALS);

?

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



Re: [PHP] $GLOBALS containing itself!!!

2003-12-15 Thread Robert Cummings
On Mon, 2003-12-15 at 04:23, Gerard Samuel wrote:
 Just curious about something I came across.
 I was looking at the $GLOBAL array, to see what my script was leaving behind.
 $GLOBALS contains a reference to itself.
 Even though its a reference, whats the sense with that??
 Once its global, why should it have to call on itself?

It's global isn't it? SOunds like completeness.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



RE: [PHP] $GLOBALS containing itself!!!

2003-12-15 Thread Wouter van Vliet
On maandag 15 december 2003 10:24 Gerard Samuel told the butterflies:
 Just curious about something I came across.
 I was looking at the $GLOBAL array, to see what my script was leaving
 behind. $GLOBALS contains a reference to itself.
 Even though its a reference, whats the sense with that??
 Once its global, why should it have to call on itself?
 Im currently running php 4.3.4 on FreeBSD 4.9
 
 Thanks
 
 A script to try out -
 ?php
 
 header('content-type: text/plain');
 
 var_dump(isset($GLOBALS['GLOBALS']['GLOBALS']));  // returns true
 
 // Prints out the $GLOBALS array
 // including one reference to itself
 // then starts another but quits with *RECURSION* var_dump($GLOBALS);
 
  

Well .. it basically just Contains a reference to every variable which is
currently available within the global scope of the script. The keys of this
array are the names of the global variables.. Since $GLOBALS itself is
global, that too is contained.

So: 


var_dump(isset($GLOBALS['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS
']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBAL
S']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBA
LS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOB
ALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLO
BALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GL
OBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['G
LOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['
GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][
'GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']
['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'
]['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS
']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBAL
S']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBA
LS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOB
ALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLO
BALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GL
OBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['G
LOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['
GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][
'GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']
['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'
]['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS
']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBAL
S']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBA
LS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOB
ALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLO
BALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GL
OBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['G
LOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['
GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'][
'GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']
['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS']['GLOBALS'
]));

Will still print out true. the displaying of *RECURSION* is to prevent, well
.. ehmm, recursively printing out the $GLOBALS array over and over again.
This is something new in PHP 4.0.4. Read the manual on page
http://nl3.php.net/manual/en/function.print-r.php:

Note: Prior to PHP 4.0.4, print_r() will continue forever if given
an array or object that contains a direct or indirect reference to itself.
An example is print_r($GLOBALS) because $GLOBALS is itself a global variable
that contains a reference to itself. 

:),
Wouter

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



[PHP] Globals set to off - Sessions

2003-10-27 Thread Steve Jackson
I am not sure what I have to do in order to  control sessions in PHP
4.33 when globals are set to off.
I used to use the following function to check if the user was of admin
status;

function check_admin_user()
// see if somebody is logged in as admin and notify them if not
{
  global $admin_user;
  if ( (session_is_registered(admin_user))  (isset($admin_user)) )
return true;
  else
return false;
} 

Then in my protected pages I would say;
if (check_admin_user())
// if you're an admin user display the following
{
Session_register(admin_user);
// Do admin functions
}
Else
{
//Do login form
}

How do I adapt the check_admin_user() function and the pages to work in
4.33?
Thanks,

Steve Jackson
Web Development and Marketing
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159

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



[PHP] Globals on/off , PHP.ini and .htaccess - Best solution?

2003-10-24 Thread Ryan A
Hi,
we have a site that is catering to webhosts and programmers, as you can
understand these people know computers and programs :-)

They are fooling around with the default settings of their accounts and
giving us funny results and basically being a PITA, asking them nicely to
quit... we are sure just wont work...so we have decided to turn globals off.
We are in the process of doing this to around 250 scripts and now we have
run into a problem...

(we are on a shared host and so dont have access to our php.ini file)
we are planning to turn globals off via a .htaccess file...nearly all our
php files are in root (/www/) , but we are also running a third party
application 1 directory above root (/www/theApplication/) which requires
globals on, when we tried to use a htaccess to turn off globals in the root
all sub directories too went off...so we added another .htaccess in  the sub
and we got errors

What to do? how can we have globals off everywhere but in the
/www/theApplication/

Cheers,
-Ryan

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



Re: [PHP] Globals on/off , PHP.ini and .htaccess - Best solution?

2003-10-24 Thread Curt Zirzow
* Thus wrote Ryan A ([EMAIL PROTECTED]):
 
 They are fooling around with the default settings of their accounts and
 giving us funny results and basically being a PITA, asking them nicely to

Put in their .htaccess something like:
  php_value engine off :)

 
 all sub directories too went off...so we added another .htaccess in  the sub
 and we got errors

What were the errors?

 
 What to do? how can we have globals off everywhere but in the
 /www/theApplication/

With the method you described above :)


Curt
-- 
My PHP key is worn out

  PHP List stats since 1997: 
http://zirzow.dyndns.org/html/mlists/

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



Re: [PHP] Globals on/off , PHP.ini and .htaccess - Best solution?

2003-10-24 Thread Eugene Lee
On Fri, Oct 24, 2003 at 02:59:58PM +0200, Ryan A wrote:
: 
: (we are on a shared host and so dont have access to our php.ini file)
: we are planning to turn globals off via a .htaccess file...nearly all our
: php files are in root (/www/) , but we are also running a third party
: application 1 directory above root (/www/theApplication/) which requires
: globals on, when we tried to use a htaccess to turn off globals in the root
: all sub directories too went off...so we added another .htaccess in  the sub
: and we got errors
: 
: What to do? how can we have globals off everywhere but in the
: /www/theApplication/

You should be able to put an .htaccess file disabling globals into /www/,
then put an .htaccess file enable globals into /www/theApplication/.  If
this setup causes problems, feel free to report back.

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



[PHP] globals on globals off (help

2003-09-16 Thread Frank Tudor
This is more for a linux group post but I know someone can
provide enlightenment on this issue.

I have the latest version of apache and php I have created my
entire sie in a foxserv environment on windows but my production
environment is on mandrake linux 9.1

The globals are set to off but i'll be damned if I know where I
can set them to on.

I found a php.ini-dist and a php.ini-recommended file but
changing these files does nothing.

can someone give me some give me a hand with this?

Thanks,
Frank

__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

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



Re: [PHP] globals on globals off (help

2003-09-16 Thread Brad Pauly
Frank Tudor wrote:
This is more for a linux group post but I know someone can
provide enlightenment on this issue.
I have the latest version of apache and php I have created my
entire sie in a foxserv environment on windows but my production
environment is on mandrake linux 9.1
The globals are set to off but i'll be damned if I know where I
can set them to on.
I found a php.ini-dist and a php.ini-recommended file but
changing these files does nothing.
can someone give me some give me a hand with this?
Create a script that outputs phpinfo().

?php
echo phpinfo();
?
This will tell you where the php.ini file should be (it probably isn't 
there right now). Copy php.ini-recommended to the location that 
phpinfo() told you it was, and name it php.ini. Make the necessary 
changes to php.ini. Restart Apache. You should be all set.

- Brad

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


Re: [PHP] globals on globals off (help

2003-09-16 Thread Jason Sheets
You can enable them on a per directory bases with .htaccess, take a look 
at http://www.php.net/manual/en/configuration.php.

I recommend using the .htaccess method rather than globally turning on 
register globals.

Jason

Frank Tudor wrote:

This is more for a linux group post but I know someone can
provide enlightenment on this issue.
I have the latest version of apache and php I have created my
entire sie in a foxserv environment on windows but my production
environment is on mandrake linux 9.1
The globals are set to off but i'll be damned if I know where I
can set them to on.
I found a php.ini-dist and a php.ini-recommended file but
changing these files does nothing.
can someone give me some give me a hand with this?

Thanks,
Frank
__
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
 

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


RE: [PHP] Globals

2003-08-04 Thread Ford, Mike [LSS]
 -Original Message-
 From: Chris Boget [mailto:[EMAIL PROTECTED]
 Sent: 01 August 2003 20:18
 
  I'm curious if someone could explain to me why this is occuring:
  
  function blah() {
//global $GLOBALS;
  echo 'Globals: pre'; print_r( $GLOBALS ); echo '/pre';
  
  }
  
  As it is shown above, with the 'global $GLOBALS' line commented
  out, the print_r() works and shows all the currently 
 defined variables
  and their corresponding values.  However, if I declare $GLOBALS
  as global, nothing gets printed out.
  
  Why?

Well, I'm kinda guessing here, but it probably goes something like this:

   global $GLOBALS;

is the equivalent of doing

   $GLOBALS = $GLOBALS['GLOBALS'];

but this causes $GLOBALS to be a local variable within the function, so the
sequence PHP executes probably goes like this:

(1) set up $GLOBALS as a local variable of the function, masking out the
true (super)global $GLOBALS.
(2) look up the 'GLOBALS' element of this new local $GLOBALS -- this is NULL
as no value has yet been assigned to the local $GLOBALS!
(3) create a reference to the NULL obtained from this lookup, and assign
that to the local $GLOBALS.

So what you've ended up in the $GLOBALS which is local to the function is a
reference to NULL, hence the behaviour you're seeing.

Like I say, this is all guesswork -- albeit slightly educated guesswork,
based on my scant and very ancient (over 20 years ago!) experience of
writing bits for a couple of interpreted languages.  Maybe a PHP internal
person might come along and tell me how close I got...!! ;)

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

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



[PHP] Globals

2003-08-01 Thread Chris Boget
I'm curious if someone could explain to me why this is occuring:

function blah() {
  //global $GLOBALS;
echo 'Globals: pre'; print_r( $GLOBALS ); echo '/pre';

}

As it is shown above, with the 'global $GLOBALS' line commented
out, the print_r() works and shows all the currently defined variables
and their corresponding values.  However, if I declare $GLOBALS
as global, nothing gets printed out.

Why?

Wouldn't the 'global $GLOBALS' line be more or less redundant in
most cases?  Because $GLOBALS is a superglobal (though, it isn't
really)?  Why would it affect whether or not $GLOBALS actually has
the expected data inside the function?

While I'm on this subject, why isn't $GLOBALS always a superglobal?
For example, this doesn't work:

function innerFunc() {

  echo $GLOBALS['blah'];

}

function outerFunc() {

  innerFunc();

}

$blah = 'bob';
outerFunc();

Nothing gets echoed from innerFunc().  Why?  If anyone can offer
any insight as to what is going on, I'd be ever so appreciative.

Chris


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



Re: [PHP] Globals

2003-08-01 Thread Jim Lucas
I can't speek about the first problem, but about the second one.

You are not setting the variable $blah as a global variable.

Try this instead

$GLOBALS['blah'] = 'bob';

and that should work.

You need to look into scope when refering to variables and functions.

Jim Lucas

- Original Message - 
From: Chris Boget [EMAIL PROTECTED]
To: PHP General [EMAIL PROTECTED]
Sent: Friday, August 01, 2003 12:03 PM
Subject: [PHP] Globals


 I'm curious if someone could explain to me why this is occuring:
 
 function blah() {
   //global $GLOBALS;
 echo 'Globals: pre'; print_r( $GLOBALS ); echo '/pre';
 
 }
 
 As it is shown above, with the 'global $GLOBALS' line commented
 out, the print_r() works and shows all the currently defined variables
 and their corresponding values.  However, if I declare $GLOBALS
 as global, nothing gets printed out.
 
 Why?
 
 Wouldn't the 'global $GLOBALS' line be more or less redundant in
 most cases?  Because $GLOBALS is a superglobal (though, it isn't
 really)?  Why would it affect whether or not $GLOBALS actually has
 the expected data inside the function?
 
 While I'm on this subject, why isn't $GLOBALS always a superglobal?
 For example, this doesn't work:
 
 function innerFunc() {
 
   echo $GLOBALS['blah'];
 
 }
 
 function outerFunc() {
 
   innerFunc();
 
 }
 
 $blah = 'bob';
 outerFunc();
 
 Nothing gets echoed from innerFunc().  Why?  If anyone can offer
 any insight as to what is going on, I'd be ever so appreciative.
 
 Chris
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


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



Re: [PHP] Globals

2003-08-01 Thread Chris Boget

 I'm curious if someone could explain to me why this is occuring:
 
 function blah() {
   //global $GLOBALS;
 echo 'Globals: pre'; print_r( $GLOBALS ); echo '/pre';
 
 }
 
 As it is shown above, with the 'global $GLOBALS' line commented
 out, the print_r() works and shows all the currently defined variables
 and their corresponding values.  However, if I declare $GLOBALS
 as global, nothing gets printed out.
 
 Why?

The above is all I really need to know.  The rest of my previous email
was the result of a massive brainfart.
Sorry about that...

Chris


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



RE: [PHP] Globals

2003-08-01 Thread Jay Blanchard
[snip]
$GLOBALS
[/snip]

From http://us2.php.net/language.variables.scope

The $GLOBALS array is an associative array with the name of the global
variable being the key and the contents of that variable being the value
of the array element. Notice how $GLOBALS exists in any scope, this is
because $GLOBALS is a superglobal.

// Superglobals are available in any scope and do 
// not require 'global'.  Superglobals are available 
// as of PHP 4.1.0

HTH!

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



Re: [PHP] Globals

2003-08-01 Thread Jim Lucas
Maybe it has to do with the fact that the $GLOBALS[] array has a copy of
itself inside the parent.

kinda weird but it looks like this

$GLOBALS['key1'] = 'value1';
$GLOBALS['key2'] = 'value2';
$GLOBALS['GLOBALS']['key1'] = 'value1';
$GLOBALS['GLOBALS']['key2'] = 'value2';

don't ask me why, but it seems odd to me to do this.  A little redundant if
you ask me.

Jim Lucas
- Original Message -
From: Chris Boget [EMAIL PROTECTED]
To: PHP General [EMAIL PROTECTED]
Sent: Friday, August 01, 2003 12:17 PM
Subject: Re: [PHP] Globals



  I'm curious if someone could explain to me why this is occuring:
 
  function blah() {
//global $GLOBALS;
  echo 'Globals: pre'; print_r( $GLOBALS ); echo '/pre';
 
  }
 
  As it is shown above, with the 'global $GLOBALS' line commented
  out, the print_r() works and shows all the currently defined variables
  and their corresponding values.  However, if I declare $GLOBALS
  as global, nothing gets printed out.
 
  Why?

 The above is all I really need to know.  The rest of my previous email
 was the result of a massive brainfart.
 Sorry about that...

 Chris


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




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



Re: [PHP] Globals

2003-08-01 Thread Jim Lucas
just to let you know, the $GLOBALS[] superglobals  was around long before
php 4.1.0

Jim Lucas
- Original Message -
From: Jay Blanchard [EMAIL PROTECTED]
To: Chris Boget [EMAIL PROTECTED]; PHP General
[EMAIL PROTECTED]
Sent: Friday, August 01, 2003 12:18 PM
Subject: RE: [PHP] Globals


[snip]
$GLOBALS
[/snip]

From http://us2.php.net/language.variables.scope

The $GLOBALS array is an associative array with the name of the global
variable being the key and the contents of that variable being the value
of the array element. Notice how $GLOBALS exists in any scope, this is
because $GLOBALS is a superglobal.

// Superglobals are available in any scope and do
// not require 'global'.  Superglobals are available
// as of PHP 4.1.0

HTH!

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




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



RE: [PHP] Globals

2003-08-01 Thread Jay Blanchard
[snip]
just to let you know, the $GLOBALS[] superglobals  was around long
before
php 4.1.0

// Superglobals are available in any scope and do
// not require 'global'.  Superglobals are available
// as of PHP 4.1.0
[/snip]

This is the quote in the online manual

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



[PHP] Globals off and passing data

2003-02-08 Thread Paul
I'm working in a multitiered envoronment in development. I'd like to turn globals off, 
but I can't figure out how to pass data back and forth between machines. I'm sending 
data to a database machine using POST, and I can use the data once it gets there, but 
I can't seem to get anything back. At the moment I'm using a meta refresh statement to 
get back to the next page on the web server on the originating machine (would like 
something more elegant than this to go to the next page, but just getting some data 
back is first on my list). Does such a thing as a tutorial exist for this?

TIA,
Paul

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




Re: [PHP] Globals off and passing data

2003-02-08 Thread Jason Wong
On Sunday 09 February 2003 06:32, Paul wrote:
 I'm working in a multitiered envoronment in development. I'd like to turn
 globals off, but I can't figure out how to pass data back and forth between
 machines. I'm sending data to a database machine using POST, and I can use
 the data once it gets there, but I can't seem to get anything back. At the
 moment I'm using a meta refresh statement to get back to the next page on
 the web server on the originating machine (would like something more
 elegant than this to go to the next page, but just getting some data back
 is first on my list). Does such a thing as a tutorial exist for this?

Perhaps you could elaborate on what your setup is and what you're doing. For 
example, what do you mean by sending data to a database machine using POST? 
The usual method of accessing a remote database does not involve the use of 
POST.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
What this country needs is a good five dollar plasma weapon.
*/


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




Re: [PHP] Globals off and passing data

2003-02-08 Thread Paul
I'm opening a socket to the remote machine and using post to send the data. But please 
enlighten me, what is the usual method of accessing a remote database?

Jason Wong wrote:
On Sunday 09 February 2003 06:32, Paul wrote:

 I'm working in a multitiered envoronment in development. I'd like to turn globals 
off, but I can't figure out how to pass data back and forth between machines. I'm 
sending data to a database machine using POST, and I can use the data once it gets 
there, but I can't seem to get anything back. At the moment I'm using a meta refresh 
statement to get back to the next page on the web server on the originating machine 
(would like something more elegant than this to go to the next page, but just getting 
some data back is first on my list). Does such a thing as a tutorial exist for this?


Perhaps you could elaborate on what your setup is and what you're doing. For example, 
what do you mean by sending data to a database machine using POST? The usual method 
of accessing a remote database does not involve the use of POST.

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




Re: [PHP] Globals off and passing data

2003-02-08 Thread Jason Wong
On Sunday 09 February 2003 07:59, Paul wrote:
 I'm opening a socket to the remote machine and using post to send the data.
 But please enlighten me, what is the usual method of accessing a remote
 database?

One usually use stuff like mysql_connect() and friends to connect to 
databases. If you're using 'post' (as in HTTP POST) then aren't you in fact 
accessing a webserver which returns data from a database as opposed to 
accessing the database directly?

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
If it heals good, say it.
*/


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




[PHP] Question about SSL/php globals

2003-01-27 Thread Wei Weng
Is there any environment/Global variable in PHP that indicates whether the
server port you connect to is SSL port?

Thanks!


Wei


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




Re: [PHP] Question about SSL/php globals

2003-01-27 Thread Philip Olson

On Mon, 27 Jan 2003, Wei Weng wrote:

 Is there any environment/Global variable in PHP that indicates whether the
 server port you connect to is SSL port?

$_SERVER['HTTPS']

Regards,
Philip


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




Re: [PHP] Question about SSL/php globals

2003-01-27 Thread Wei Weng
Thanks for the prompt reply!

One more question, do you know how PHP implements this variable? In other words,
how does PHP detect whether the connection is SSLed or not? (Specific to apache)

Thanks!

Wei


- Original Message -
From: Philip Olson [EMAIL PROTECTED]
To: Wei Weng [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Monday, January 27, 2003 12:19 PM
Subject: Re: [PHP] Question about SSL/php globals



 On Mon, 27 Jan 2003, Wei Weng wrote:

  Is there any environment/Global variable in PHP that indicates whether the
  server port you connect to is SSL port?

 $_SERVER['HTTPS']

 Regards,
 Philip


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




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




[PHP] globals off in function

2003-01-14 Thread Michael Bevz
Hi, all!!!
I've such trouble:
( register_globals = off )

in function i call to $smarty variable

function showLoginForm(){

   global $db, $smarty; // $smarty = new Smarty in main code

  $smarty-assign(message, $message); // 

and i receive this error message

Fatal error: Call to a member function on a non-object in
/usr/home/elastic.org/work/svyatoshin/system/common_func.php on line 22


Imho, globals don't working with globals off, nut i can't find this in
manual.

Who can help me?



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




Re: [PHP] globals off in function

2003-01-14 Thread Jason Wong
On Tuesday 14 January 2003 18:46, Michael Bevz wrote:

 I've such trouble:
 ( register_globals = off )

The register_globals setting in php.ini has ...

 in function i call to $smarty variable
 
 function showLoginForm(){

global $db, $smarty; // $smarty = new Smarty in main code

... nothing to do with the 'global' statement.

   $smarty-assign(message, $message); // 
 
 and i receive this error message
 
 Fatal error: Call to a member function on a non-object in
 /usr/home/elastic.org/work/svyatoshin/system/common_func.php on line 22
 

 Who can help me?

Assuming line 22 is (it would help if you told us _which_ is line 22)

  $smarty-assign(message, $message);

and assuming that you _really_ have defined $smarty in the main code then I 
cannot see what you're doing wrong.

Does $smarty-assign(message, $message work in the main loop (ie when not in 
a function)?

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
In Oz, never say krizzle kroo to a Woozy.
*/


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




Re: [PHP] globals off in function

2003-01-14 Thread Chris Hayes


in function i call to $smarty variable

function showLoginForm(){

   global $db, $smarty; // $smarty = new Smarty in main code
Fatal error: Call to a member function on a non-object in


Are you sure
$smarty = new Smarty
is in the main code?
Can it be in another function?

Try setting
global $smarty;
just before you create $smarty.

Does that help?


( register_globals = off )
Imho, globals don't working with globals off, nut i can't find this in
manual.

no, register_globals is only about the automatical production of variables 
from FORM, GET and other data input.
But i fully agree the name is confusing.


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



Re: [PHP] globals off in function

2003-01-14 Thread Michael Bevz

Chris Hayes [EMAIL PROTECTED] ïèøåò â
ñîîáùåíèè:[EMAIL PROTECTED]

 in function i call to $smarty variable
 
 function showLoginForm(){
 
 global $db, $smarty; // $smarty = new Smarty in main code
 Fatal error: Call to a member function on a non-object in

 Are you sure
 $smarty = new Smarty
 is in the main code?
 Can it be in another function?

 Try setting
 global $smarty;
 just before you create $smarty.

 Does that help?
Thanks, that's nice help :)


 ( register_globals = off )
 Imho, globals don't working with globals off, nut i can't find this in
 manual.
 no, register_globals is only about the automatical production of variables
 from FORM, GET and other data input.
 But i fully agree the name is confusing.




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




[PHP] globals not working?

2002-10-04 Thread Paul Kaiser

I have an odd problem.

I have a file called evt_to_web.php. This file contains some variable
assignments and a few functions.

I have used
require_once evt_to_web.php;
in another file, indextest.php.
In indextest.php, I then call a function that is in evt_to_web.php.

That function cannot seem to see it's own global variables, even though I
have used global etc;.

I'm pulling my hair out.

Here is evt_to_web.php:

$evthostname = localhost;
$evtusername = paukai;
$evtpassword = imctiger88;
$evtdatabase = imc_evts;
$evtevents_table = evt_events; // Table where all events will be stored.
$evtclient_table = evt_clients; // The owners of events and their login
info
$evtcategory_table = evt_cats; // Small table with categories for event
sorting

// Administration password
$evtadmin_password = imccalendar;

$evtimg_dir = images/;

// Webmaster, in case of error:
$evtwebmaster = [EMAIL PROTECTED];

// Redir site in case of error:
$evtredir_site = http://www.illinimedia.com/;;

function testGlobal() {
global $evtredir_site;

echo TestGlobal: '$evtredir_site'br\n;
}

When I do testGlobal(); I get:

TestGloal: ''

Showing me that the function testGlobal thinks that $everedir_site is empty.

What have I done wrong here??

Thanks,
Paul Kaiser




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




RE: [PHP] globals not working?

2002-10-04 Thread Jon Haworth

Hi Paul,

 function testGlobal() {
   global $evtredir_site;
 
   echo TestGlobal: '$evtredir_site'br\n;
 }
 
 When I do testGlobal(); I get:
 
 TestGloal: ''


Change this function to:

  function testGlobal() {
global $evtredir_site;
echo TestGlobal: . $evtredir_site. br\n;
  }

Cheers
Jon

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




[PHP] $GLOBALS ???

2002-07-05 Thread Scott Fletcher

Let's say .

--clip--
Page 1 -
$data = Yes!;

header(Location: test1.php);

Page 2 -
$data = $GLOBALS['data'];

echo $data;

--clip--

This one does not work!  Does this ever work at all or do I need to do the
header(Location: test1.php?data=Yes!); into the script?




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




RE: [PHP] $GLOBALS ???

2002-07-05 Thread Lazor, Ed

Correct you can add the data as a URL parameter.  Or, you could set a
cookie and use sessions.

-Original Message-

Let's say .

--clip--
Page 1 -
$data = Yes!;

header(Location: test1.php);

Page 2 -
$data = $GLOBALS['data'];

echo $data;

--clip--

This one does not work!  Does this ever work at all or do I need to do the
header(Location: test1.php?data=Yes!); into the script?




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

This message is intended for the sole use of the individual and entity to
whom it is addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law.  If you are
not the intended addressee, nor authorized to receive for the intended
addressee, you are hereby notified that you may not use, copy, disclose or
distribute to anyone the message or any information contained in the
message.  If you have received this message in error, please immediately
advise the sender by reply email and delete the message.  Thank you very
much.   

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




Re: [PHP] $GLOBALS ???

2002-07-05 Thread Scott Fletcher

Oh boy!  Alright!  URL it is

Ed Lazor [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Correct you can add the data as a URL parameter.  Or, you could set a
 cookie and use sessions.

 -Original Message-

 Let's say .

 --clip--
 Page 1 -
 $data = Yes!;

 header(Location: test1.php);

 Page 2 -
 $data = $GLOBALS['data'];

 echo $data;

 --clip--

 This one does not work!  Does this ever work at all or do I need to do the
 header(Location: test1.php?data=Yes!); into the script?




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



 This message is intended for the sole use of the individual and entity to
 whom it is addressed, and may contain information that is privileged,
 confidential and exempt from disclosure under applicable law.  If you are
 not the intended addressee, nor authorized to receive for the intended
 addressee, you are hereby notified that you may not use, copy, disclose or
 distribute to anyone the message or any information contained in the
 message.  If you have received this message in error, please immediately
 advise the sender by reply email and delete the message.  Thank you very
 much.



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




Re: [PHP] $GLOBALS ???

2002-07-05 Thread Scott Fletcher

What about PHPSESSID???  Can't use the $_COOKIE.

Thanks,
 FletchSOD

Ed Lazor [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Correct you can add the data as a URL parameter.  Or, you could set a
 cookie and use sessions.

 -Original Message-

 Let's say .

 --clip--
 Page 1 -
 $data = Yes!;

 header(Location: test1.php);

 Page 2 -
 $data = $GLOBALS['data'];

 echo $data;

 --clip--

 This one does not work!  Does this ever work at all or do I need to do the
 header(Location: test1.php?data=Yes!); into the script?




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



 This message is intended for the sole use of the individual and entity to
 whom it is addressed, and may contain information that is privileged,
 confidential and exempt from disclosure under applicable law.  If you are
 not the intended addressee, nor authorized to receive for the intended
 addressee, you are hereby notified that you may not use, copy, disclose or
 distribute to anyone the message or any information contained in the
 message.  If you have received this message in error, please immediately
 advise the sender by reply email and delete the message.  Thank you very
 much.



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




RE: [PHP] $GLOBALS ???

2002-07-05 Thread Lazor, Ed

I don't understand.  What do you mean?

-Original Message-
What about PHPSESSID???  Can't use the $_COOKIE.
 

This message is intended for the sole use of the individual and entity to
whom it is addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law.  If you are
not the intended addressee, nor authorized to receive for the intended
addressee, you are hereby notified that you may not use, copy, disclose or
distribute to anyone the message or any information contained in the
message.  If you have received this message in error, please immediately
advise the sender by reply email and delete the message.  Thank you very
much.   

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




RE: [PHP] $GLOBALS ???

2002-07-05 Thread Lazor, Ed

Is this true? :

Session variables are tracked whether or not a visitor's browser supports
cookies.  The session id is automatically appeneded to each url on the site
if the user's browser doesn't support cookies.

This represents one of the major differences between setting your own
cookies and using sessions.

-Original Message-
Haven't seen this post on PHP newsgroup.  What I mean by that is, let's say
I use the header(Location: test.php?SIDdata=Yes!);.  I now know that I
would have to use the data in the URL.  But for SID, this will apply but I
want to know is, is there any PHP code that will do this behind the scene
without needing to use the URL.  $_COOKIE can do this but I can't use
$_COOKIE because if the user's browser had the cookie disabled, then it
wouldn't do me any good.
 

This message is intended for the sole use of the individual and entity to
whom it is addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law.  If you are
not the intended addressee, nor authorized to receive for the intended
addressee, you are hereby notified that you may not use, copy, disclose or
distribute to anyone the message or any information contained in the
message.  If you have received this message in error, please immediately
advise the sender by reply email and delete the message.  Thank you very
much.   

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




Re: [PHP] Globals bug??

2002-07-01 Thread Marek Kilimajer

Are you using any opcode cache? Are you sure it is another process or 
might it be another thread.

Marek

[EMAIL PROTECTED] wrote:

We are seeing a rare bug that seems to imply that there is a bug in PHP's
global variables across httpd processes. To make a long story short, it 
appears that on rare occassions our script gets the value of a HTTP_GET_VARS
variable from another user's process. Is this possible? BTW, it seems to occur
when using HTTP_GET_VARS and the new 'super globals'.

FWIW, we're using PHP 4.1.2 on (Red Hat) Linux 2.4.9 with Apache 1.3.12.

Thanks!

(please reply via email in addition to posting here if possible)



  




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




Re: [PHP] Globals bug??

2002-07-01 Thread troy

When I said process I meant request. Sorry. Is it possible that the PHP
globals are being used across requests (i.e., within the same process)? We
noticed this when upgrading from a version of PHP (4.0.6?) prior to the new
super-globals being added to PHP 4.1.2. 

The code in this case is so straightforward that I can't see any other
explanation. The variable in question comes from the URL. For example, if the
URL is http://foo.com/page.php?var=abc, $var in the PHP is a different value 
in these rare cases.  And the variable we use here is in a very specific 
format and it is a valid value just that it's a different value from the one 
in the URL. 

Also note that we've only seen this problem when the variable has a longer
string than the one in the URL. Using the URL from the above example again,
$var has a value like abcdef which is valid value but longer (in addition to
being wrong). It's as if PHP is re-using memory from a previous request and is
not truncating the string properly for the next request.

Does that make more sense? Possible?


Rasmus Lerdorf [EMAIL PROTECTED] wrote:
 I don't see how.  But if what you are saying is actually happening, then
 it is a Linux kernel-level bug if memory is leaking from one process to
 another.  No matter how badly we screwed up in PHP, the kernel prevents
 such a screwup from infecting a separate process.

 I'd suggest having a close look at your code.

 -Rasmus

 On 30 Jun 2002 [EMAIL PROTECTED] wrote:

 We are seeing a rare bug that seems to imply that there is a bug in PHP's
 global variables across httpd processes. To make a long story short, it
 appears that on rare occassions our script gets the value of a HTTP_GET_VARS
 variable from another user's process. Is this possible? BTW, it seems to occur
 when using HTTP_GET_VARS and the new 'super globals'.

 FWIW, we're using PHP 4.1.2 on (Red Hat) Linux 2.4.9 with Apache 1.3.12.

 Thanks!

 (please reply via email in addition to posting here if possible)



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



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




[PHP] Globals bug??

2002-06-30 Thread troy

We are seeing a rare bug that seems to imply that there is a bug in PHP's
global variables across httpd processes. To make a long story short, it 
appears that on rare occassions our script gets the value of a HTTP_GET_VARS
variable from another user's process. Is this possible? BTW, it seems to occur
when using HTTP_GET_VARS and the new 'super globals'.

FWIW, we're using PHP 4.1.2 on (Red Hat) Linux 2.4.9 with Apache 1.3.12.

Thanks!

(please reply via email in addition to posting here if possible)



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




Re: [PHP] Globals bug??

2002-06-30 Thread Rasmus Lerdorf

I don't see how.  But if what you are saying is actually happening, then
it is a Linux kernel-level bug if memory is leaking from one process to
another.  No matter how badly we screwed up in PHP, the kernel prevents
such a screwup from infecting a separate process.

I'd suggest having a close look at your code.

-Rasmus

On 30 Jun 2002 [EMAIL PROTECTED] wrote:

 We are seeing a rare bug that seems to imply that there is a bug in PHP's
 global variables across httpd processes. To make a long story short, it
 appears that on rare occassions our script gets the value of a HTTP_GET_VARS
 variable from another user's process. Is this possible? BTW, it seems to occur
 when using HTTP_GET_VARS and the new 'super globals'.

 FWIW, we're using PHP 4.1.2 on (Red Hat) Linux 2.4.9 with Apache 1.3.12.

 Thanks!

 (please reply via email in addition to posting here if possible)



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



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




Re: [PHP] Accessing PHP globals from a module.

2002-05-22 Thread Eric Veldhuyzen

On Tue, May 21, 2002 at 08:03:36AM -0700, Rasmus Lerdorf wrote:
 Depends a bit on what sort of globals you are after.  If you mean a global
 variable set by the user in the global symbol table you would do:
 
   pval **tmp;
   if(zend_hash_find(EG(symbol_table), foo, 3, (void **)tmp) == SUCCESS) {
 RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
   } else {
 RETURN_FALSE;
   }
 
 Would fetch $foo from the global symbol table, stick it in tmp and return
 it from your function.

I might be able to use this, but what I am really after is getting
values from the session variables, like $_SESSION[id]. Is this
possible at all and if so, is this documented somewhere? 

 On Tue, 21 May 2002, Eric Veldhuyzen wrote:
 
  Hi,
 
  I have just written a module for PHP (in C, linked with PHP statically).
  Now I need to access session variables and other globals from whithin my
  module. But I can't find how I should do this, I see documentation on
  how
  to call user functions, and how to create new global varables, but now
  how to access existing globals. Could somebody please tell me where
  tell me where this is documented if it is documented at all, or explain
  it to me if it is not documented yet?

-- 
#!perl #   Life ain't fair, but root passwords help.
# Eric Veldhuyzen  [EMAIL PROTECTED]
$!=$;=$_+(++$_);($:,$~,$/,$^,$*,$@)=$!=~   # Perl Monger
/.(.)...(.)(.)(.)..(.)..(.)/;`$^$~$/$: $^$*$@$~ $_$;`

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




Re: [PHP] Accessing PHP globals from a module.

2002-05-22 Thread Rasmus Lerdorf

 On Tue, May 21, 2002 at 08:03:36AM -0700, Rasmus Lerdorf wrote:
  Depends a bit on what sort of globals you are after.  If you mean a global
  variable set by the user in the global symbol table you would do:
 
pval **tmp;
if(zend_hash_find(EG(symbol_table), foo, 3, (void **)tmp) == SUCCESS) {
  RETURN_STRINGL(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
} else {
  RETURN_FALSE;
}
 
  Would fetch $foo from the global symbol table, stick it in tmp and return
  it from your function.

 I might be able to use this, but what I am really after is getting
 values from the session variables, like $_SESSION[id]. Is this
 possible at all and if so, is this documented somewhere?

Yup, in ext/session/session.c

-Rasmus


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




[PHP] Accessing PHP globals from a module.

2002-05-21 Thread Eric Veldhuyzen

Hi,

I have just written a module for PHP (in C, linked with PHP statically).
Now I need to access session variables and other globals from whithin my
module. But I can't find how I should do this, I see documentation on how
to call user functions, and how to create new global varables, but now
how to access existing globals. Could somebody please tell me where
tell me where this is documented if it is documented at all, or explain
it to me if it is not documented yet?

-- 
#!perl #   Life ain't fair, but root passwords help.
# Eric Veldhuyzen  [EMAIL PROTECTED]
$!=$;=$_+(++$_);($:,$~,$/,$^,$*,$@)=$!=~   # Perl Monger
/.(.)...(.)(.)(.)..(.)..(.)/;`$^$~$/$: $^$*$@$~ $_$;`

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




[PHP] Accessing PHP globals from a module.

2002-05-21 Thread Eric Veldhuyzen

Hi,

I have just written a module for PHP (in C, linked with PHP statically).
Now I need to access session variables and other globals from whithin my
module. But I can't find how I should do this, I see documentation on
how
to call user functions, and how to create new global varables, but now
how to access existing globals. Could somebody please tell me where
tell me where this is documented if it is documented at all, or explain
it to me if it is not documented yet?

-- 
#!perl #   Life ain't fair, but root passwords help.
# Eric Veldhuyzen  [EMAIL PROTECTED]
$!=$;=$_+(++$_);($:,$~,$/,$^,$*,$@)=$!=~   # Perl Monger
/.(.)...(.)(.)(.)..(.)..(.)/;`$^$~$/$: $^$*$@$~ $_$;`

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




Re: [PHP] globals in functions

2002-04-15 Thread Erik Price


On Saturday, April 13, 2002, at 01:37  PM, Paul Roberts wrote:

 Is there a quick way to set all variables as global so that they are 
 avalible to a function, i'm doing an eval inside, so i need all the 
 submitted variables to be avalible, or do i have to decalre them 
 individualy.

If you refer to a POST or GET (or COOKIE or SESSION or SERVER) variable 
as $_POST['variablename'] or $_GET['variablename'], then it will 
automatically be global.

In PHP 4.1.x or later


Erik






Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




[PHP] globals in functions

2002-04-13 Thread Paul Roberts

Is there a quick way to set all variables as global so that they are avalible to a 
function, i'm doing an eval inside, so i need all the submitted variables to be 
avalible, or do i have to decalre them individualy.

Paul Roberts
[EMAIL PROTECTED]





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




RE: [PHP] globals in functions

2002-04-13 Thread Cal Evans

1: Globals are bad...m'kay.
You should never use globals.  If your function needs a variable, you should
pass it in. There are exceptions to this rule but it's not a good idea to
program normally this way.

2: Is this a form?
It sounds (from the way you word it) that the variables are part of a form.
If so, pass $_POST into your form and it will be able to evaluate them.  If
it's METHOD=GET then use $_GET.  This is also a much more generic way to
program since if you add a new variable to the form, you don't have to make
it global in this function.

if (myFunction($_GET)){
echo Everything is hunky dory!;
} else {
echo Blow Chow;
}

function myFunction($formArray=null){
if (isNull($formArray){
return false;
}

if (isarray($formArray)){
return true;
} else {
return false;
}
} // function myFunction($formArray=null)

WARNING: I have not tried the code above.  Use at your own risk.  But the
concepts are there.
*
* Cal Evans
* Journeyman Programmer
* Techno-Mage
* http://www.calevans.com
*


-Original Message-
From: Paul Roberts [mailto:[EMAIL PROTECTED]]
Sent: Saturday, April 13, 2002 12:37 PM
To: [EMAIL PROTECTED]
Subject: [PHP] globals in functions


Is there a quick way to set all variables as global so that they are
avalible to a function, i'm doing an eval inside, so i need all the
submitted variables to be avalible, or do i have to decalre them
individualy.

Paul Roberts
[EMAIL PROTECTED]





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



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




[PHP] globals not working for me with 4.1.0

2002-01-08 Thread Matt Pieklik

Hello,
I had a script that was workin for me with PHP 4.0.6.
I upgraded to 4.1.0 because another app required it,
and it broke the original script I was using.
Under 4.0.6 I was able to do the following:

global $PHP_AUTH_USER,$PHP_AUTH_PW;
echo $GLOBALS[REMOTE_ADDR];

This would echo the correct results.  Now after the
upgrade, the code above does not echo anything.
This will work, however:
 
echo $_SERVER[REMOTE_ADDR];

In my php.ini I have the following:
register_globals = On
register_argc_argv = On


Any ideas on how to fix these global variables not being
set?

Thanks,
Matt

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] $GLOBALS array

2001-12-23 Thread Philip MacIver

Does anyone know if it is possible to use the 

'global $varName'

function with the '$GLOBALS' array itself.

I have been having some trouble with this. I have decieded to switch of 
register_globals in the php.ini file (seeing as
it is now deprecated in version 4.1.0)
I know that register_globals is still supported, but I would like to get used to not 
using it.
But anyway, the problem I am having is that when I post data from a form to another 
page the data is not available
globally, so I wrote a method to register them globally, it looks like this

function globaliseVars($varArray) {
global $GLOBALS;

while (list($varName,$var) = each($varArray)) {
$GLOBALS[trim($varName)] = trim($var);
}
}

But doing 'global $GLOBALS' doesn't seem to make it refer to the actual '$GLOBALS' 
array, the only time it did work was
when I place something into the '$GLOBALS' array on the page that calls the function. 
So

/**
* This doesn't work
*/
globaliseVars($HTTP_POST_VARS);


/**
* But this does
*/
$GLOBALS[ANYTHING] = anything;
globaliseVars($HTTP_POST_VARS);

If anyone could help me with this problem please could they get in touch, because its 
driving me crazy.

Thanks!

==
Philip MacIver   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] $GLOBALS

2001-11-13 Thread PACKER, Steffan

If you use a form with method=GET and submit it all the field names and
values are stored in a global associative array called HTTP_GET_VARS as
name/value pairs.

Steffan

-Original Message-
From: Peter Tilm [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 13, 2001 2:16 PM
To: [EMAIL PROTECTED]
Subject: [PHP] $GLOBALS


hi,

i´m new in PHP. What does the expression:
   $ref=$GLOBALS[HTTP_GET_VARS][ref];
   $id=$GLOBALS[HTTP_GET_VARS][id];
do?

What is $GLOBALS?
What are the parameters [HTTP_GET_VARS][ref]?

thanks
Peter

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


_
This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp



DISCLAIMER

Any opinions expressed in this email are those of the individual
and not necessarily the company.  This email and any files 
transmitted with it, including replies and forwarded copies (which
may contain alterations) subsequently transmitted from the 
Company, are confidential and solely for the use of the intended
recipient.  It may contain material protected by attorney-client
privilege.  If you are not the intended recipient or the person
responsible for delivering to the intended recipient, be advised
that you have received this email in error and that any use is
strictly prohibited.

If you have received this email in error please notify the Network
Manager by telephone on +44 (0) 870 243 2431.

Please then delete this email and destroy any copies of it.
This email has been swept for viruses before leaving our system.

Admiral Insurance Services Limited, Cardiff CF10 3AZ



_
This message has been checked for all known viruses by the
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp



Re: [PHP] $GLOBALS

2001-11-13 Thread Emil Rasmussen

 i´m new in PHP. What does the expression:
$ref=$GLOBALS[HTTP_GET_VARS][ref];
$id=$GLOBALS[HTTP_GET_VARS][id];
 do?

It gives you the content of the querystring variable ref and id. eg.
page.php?id=20ref=value

 What is $GLOBALS?

$GLOBALS is an array wich contains all the varibles in the global variable
scope. http://dk.php.net/manual/en/language.variables.scope.php

You can get an overview of all the variables by using the print_r()
function: print_r($GLOBALS);
http://dk.php.net/manual/en/function.print-r.php

 What are the parameters [HTTP_GET_VARS][ref]?

[HTTP_GET_VARS] is also an array, and it contains alle the variables from
the querystring. And ['ref'] is a querystring variable.

/Emil
--
Emil Rasmussen
http://noget.net


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] $GLOBALS

2001-11-13 Thread Peter Tilm

hi,

i´m new in PHP. What does the expression:
   $ref=$GLOBALS[HTTP_GET_VARS][ref];
   $id=$GLOBALS[HTTP_GET_VARS][id];
do?

What is $GLOBALS?
What are the parameters [HTTP_GET_VARS][ref]?

thanks
Peter

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Globals and HTTP_SESSION_VARS variables.

2001-09-26 Thread Johnson, Kirk

 Is here anyway to make a variable like $var not the same than
 $HTTP_SESSION_VARS[var], when register_globals=1?. (where 
 $var is in the
 script scope).
 
 I read in a changelog that this is relatively recent (make 
 $var the same
 than $HTTP_SESSION_VARS[var]).

I'm not sure what was changed. As far as I can see, the global version of
$test and $HTTP_SESSION_VARS[test] still reference different memory
locations, and they are not the same variable, *while on the current page*.
However, if register_globals is on, then the global version gets saved to
the session file, and will be in the $HTTP_SESSION_VARS array on the next
page.

?
session_start();
$test=globalversion;
session_register(test);
$HTTP_SESSION_VARS[test] = arrayversion;
echo global version of test = $testbr;
echo sess array version of test = .$HTTP_SESSION_VARS[test].br;
?

Kirk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Globals and HTTP_SESSION_VARS variables.

2001-09-25 Thread Rodolfo Gonzalez Gonzalez

Hi,

Is here anyway to make a variable like $var not the same than
$HTTP_SESSION_VARS[var], when register_globals=1?. (where $var is in the
script scope).

I read in a changelog that this is relatively recent (make $var the same
than $HTTP_SESSION_VARS[var]).

Thank you.

Regards,
Rodolfo.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] PHP globals aren't really globals

2001-02-16 Thread php3

Addressed to: Maxim Maletsky [EMAIL PROTECTED]
  [EMAIL PROTECTED]
  Christian Dechery [mailto:[EMAIL PROTECTED]]

** Reply to note from Maxim Maletsky [EMAIL PROTECTED] Fri, 16 Feb 2001 
12:18:27 +0900

 I never used 50 of them, but I think there's such a thing as 'register
 globals' wchich makes all if the globals become available inside your
 funcs..  no idea how to use it ... I feel like I've seen it in =
 someone
 else's code ...

 correct me if I am wrong ...

Consider your self corrected...   :)


register_globals is about placing GET/PUT/COOKIE/ENVIRONMENT variables into the
global scope.  It has nothing to do with functions.


Rasmus explained why you need to declare variables as global in EVERY function
that uses them here:

  http://marc.theaimsgroup.com/?l=php-generalm=97984136422910w=2

and here:

  http://marc.theaimsgroup.com/?l=php-generalm=97717866712033w=2

You may as well get used to it, it isn't going to change any time soon...




Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] PHP globals aren't really globals

2001-02-15 Thread Maxim Maletsky

I never used 50 of them, but I think there's such a thing as 'register
globals' wchich makes all if the globals become available inside your
funcs..  no idea how to use it ... I feel like I've seen it in someone
else's code ...

correct me if I am wrong ...  

Cheers,
Maxim Maletsky



-Original Message-
From: Christian Dechery [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 14, 2001 11:25 PM
To: [EMAIL PROTECTED]
Subject: [PHP] PHP globals aren't really globals


I've been programming in C all my life, and now I just started developing
in PHP and I'm really enjoying it, it has all the missing improvements that
C needed to be more user-likely. 

But one thin I can't get, how can PHP call a variabel global, if it isn't
global.
A global var, is a var defined outside all functions and it's available
to all and altered by all, without having to redefine or call the var again.

In PHP, for a var to be global you have to add a 'global $var' inside the
function u want to use it. THis is not nice, what about if u have a form
with 50 fields and want a function to validate all of them, u have to pass
them all to the function or build a little piece of code to make all th
$GLOBALS local right?

Is this really the idea of global vars?


. [ Christian Dechery  ]
. Webdeveloper @ T Na Mesa!
. Listmaster @ Gaita-L
. http://www.tanamesa.com.br



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP globals aren't really globals

2001-02-14 Thread Thierry Coopman

At 11:24 AM -0300 2/14/01, Christian Dechery wrote:
I've been programming in C all my life, and now I just started developing
in PHP and I'm really enjoying it, it has all the missing improvements that
C needed to be more user-likely.

But one thin I can't get, how can PHP call a variabel global, if it isn't
global.
A global var, is a var defined outside all functions and it's available
to all and altered by all, without having to redefine or call the var again.

In PHP, for a var to be global you have to add a 'global $var' inside the
function u want to use it. THis is not nice, what about if u have a form
with 50 fields and want a function to validate all of them, u have to pass
them all to the function or build a little piece of code to make all th
$GLOBALS local right?

Is this really the idea of global vars?


Well having a form with LOTS of fields, it might be advisable to have 
the fields send an array straigt away

have the name of your fields something like .. name="feedback[name]" 
.. and just use global $feedback and the whole array is at your 
disposition.

This doens't change the way global is treated in PHP but might help 
you in your setup. having these in an array will also greatly make 
sessions easier, if you have to follow all these fields on multiple 
pages.

-- 
Thierry Coopman - [EMAIL PROTECTED]
My opinions are personal, and have really nothing or nothing to do 
with Keytrade!

He who laughs last probably made a back-up.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] PHP globals aren't really globals

2001-02-14 Thread Boget, Chris

 function u want to use it. THis is not nice, what about if u 
 have a form with 50 fields and want a function to validate 
 all of them, u have to pass them all to the function or build 
 a little piece of code to make all the $GLOBALS local right?
 Is this really the idea of global vars?

Yes.  But with regards to form variables, all you need to do is
make one variable global:

$HTTP_POST_VARS

it is an associative array that contains all the post variables from 
the form.  Make it global and just loop through it.

Chris



RE: [PHP] PHP globals aren't really globals

2001-02-14 Thread Christian Dechery

 function u want to use it. THis is not nice, what about if u
 have a form with 50 fields and want a function to validate
 all of them, u have to pass them all to the function or build
 a little piece of code to make all the $GLOBALS local right?
 Is this really the idea of global vars?

Yes.  But with regards to form variables, all you need to do is
make one variable global:

$HTTP_POST_VARS

it is an associative array that contains all the post variables from
the form.  Make it global and just loop through it.

exactly, u need to loop to an array to get the globals u want.
this is not the idea of global, global is global... if it's set outside
of ALL functions it should be available 'with no extra code' to ALL functions,
it works that way in all programming language I'm familiar with... why not
in PHP? that's what I wanna know, why globals in PHP doesn't really work
like globals?


. [ Christian Dechery  ]
. Webdeveloper @ T Na Mesa!
. Listmaster @ Gaita-L
. http://www.tanamesa.com.br



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] PHP globals aren't really globals

2001-02-14 Thread Boget, Chris

 Yes.  But with regards to form variables, all you need to do is
 make one variable global:
 $HTTP_POST_VARS
 it is an associative array that contains all the post variables from 
 the form.  Make it global and just loop through it.

 exactly, u need to loop to an array to get the globals u want.

No, to the the variables/values that you want.

 this is not the idea of global, global is global... if it's set outside
 of ALL functions it should be available 'with no extra code' 
 to ALL functions, it works that way in all programming language 
 I'm familiar with... why not in PHP? that's what I wanna know, 
 why globals in PHP doesn't really work like globals?

Perhaps I'm missing something.  In order to access the value of any
variable defined outside the scope of the function, you have to declare
it as "global".  This is true in every single instance.  If you do not, then
you cannot access the value of that variable.  While it's been a while
since I've worked with C, I seem to recall it being the case there as
well.  And in Pascal.  And in VB.  Again, it's been a while so I could be
wrong (but don't think so).  
Also, PHP was written in C.  Why would they institute a behaviour 
that was radically different than what is part of the parent language?

Chris



Re: [PHP] PHP globals aren't really globals

2001-02-14 Thread Rasmus Lerdorf

 I've been programming in C all my life, and now I just started developing
 in PHP and I'm really enjoying it, it has all the missing improvements that
 C needed to be more user-likely.

 But one thin I can't get, how can PHP call a variabel global, if it isn't
 global.
 A global var, is a var defined outside all functions and it's available
 to all and altered by all, without having to redefine or call the var again.

That may be your definition of a global variable.  It isn't mine.  The
fact that you have some way to access the variable from every scope makes
it global by my definition.

Also, all global variables are available via $GLOBALS['var_name'].  And if
you really do have 50 global variables, you should really appreciate this
feature as your chances of having local/global variable overlaps which can
cause weird bugs is that much higher.  I would suggest grouping your
variables into logical arrays of information and doing a 'global' on these
arrays instead.

 In PHP, for a var to be global you have to add a 'global $var' inside the
 function u want to use it. THis is not nice, what about if u have a form
 with 50 fields and want a function to validate all of them, u have to pass
 them all to the function or build a little piece of code to make all th
 $GLOBALS local right?

If you have a form with 50 fields, name them like this:

input type="text" name="blah[abc]"
input type="text" name="blah[def]"
input type="text" name="blah[ghi]"

Then simply make do: global $blah

 Is this really the idea of global vars?

The idea is to avoid really nasty scope-related bugs that are common in C
code that uses lots of global variables.  Years and years ago when I wrote
the first version of PHP I was working for a telco writing software for a
large telephone switch.  The code was huge and extremely ugly.  Global
variables everywhere.  The team had been chasing a bug for about a week
when I got stubborn and decided it was time to kill the bug.  I printed
out all the source code and laid it out in a long hallway as I crawled
along with different coloured pens and manually traced my way through it
as none of the debuggers we had at the time were of any use.  After
countless hours the bug turned out to be inside a function that silently
modified a global variable which affected another piece of code in a
completely different part of the program.

I swore I would not have the same problem in PHP and thus the requirement
for people to be explicit about using global variables inside functions.
Hopefully it also forces a little bit of structure and organization on
people.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP globals aren't really globals

2001-02-14 Thread John Vanderbeck

 Perhaps I'm missing something.  In order to access the value of any
 variable defined outside the scope of the function, you have to declare
 it as "global".  This is true in every single instance.  If you do not,
then
 you cannot access the value of that variable.  While it's been a while
 since I've worked with C, I seem to recall it being the case there as
 well.  And in Pascal.  And in VB.  Again, it's been a while so I could be
 wrong (but don't think so).

Not realy.  In most languages, heck , all I can think of, the variable's
scope is simply dependant on WHERE it was declared, not how it was declared.
If in C/C++ you define a variable outside the scope of any function, then it
becomes global and can be accessed by any function.

I'm not arguing one side or the other, just stating :) I personally find the
PHP way a bit annoiying, but its workable, and i'm SURE there was a reason
for it.  Just not sure what that reason was :)

- John Vanderbeck
- Admin, GameDesign


 Chris



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP globals aren't really globals

2001-02-14 Thread Rog

Rasmus wrote:
 I swore I would not have the same problem in PHP and thus the requirement
 for people to be explicit about using global variables inside functions.
 Hopefully it also forces a little bit of structure and organization on
 people.

Hear, hear and thank you Rasmus. It seems to me that the several other ways 
folks have listed to solve this one example indicates that we don't really 
need the temporary convenience of wide open globals (temporary as in it 
doesn't end up very convenient when they create problems).


 Visit the Gates Motel webgame:
 http://www.gameslate.com/gatesmotel/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP globals aren't really globals

2001-02-14 Thread John Vanderbeck

 Rasmus wrote:
  I swore I would not have the same problem in PHP and thus the
requirement
  for people to be explicit about using global variables inside functions.
  Hopefully it also forces a little bit of structure and organization on
  people.

 Hear, hear and thank you Rasmus. It seems to me that the several other
ways
 folks have listed to solve this one example indicates that we don't really
 need the temporary convenience of wide open globals (temporary as in it
 doesn't end up very convenient when they create problems).

I was always tought very simply, don't use globals :)

However, that isn't always an option.  I have no problems with the way PHP
does things.  I think its a good idea for the shelter. What I find
interesting is that it seems when you are first learning a language, you use
more globals, than when you are more experienced with it.  When I first
started programmig in C, 99% of my variables were global.  Look at any of my
C/C++ code nowadays, over 10 years later, and you will be hard pressed to
find a global.

PHP is still new to me, so i'm still trying to use alot of globals.  Because
of the way PHP handles it, i'm jumping through a few hoops.  That is
annoying, but I don't consider it a problem, because as I get better, I know
I will go back through and rewrite things to not use globals.  I guess my
confusion is this: I am passing all my variables around between scripts by
sending them through the URLs (index.php?mode=index).  I guess what "annoys"
me, is I would expect those to be available from inside the functions, but
they aren't.

- John Vanderbeck
- Admin, GameDesign


  Visit the Gates Motel webgame:
  http://www.gameslate.com/gatesmotel/


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP globals aren't really globals

2001-02-14 Thread Christian Dechery


The idea is to avoid really nasty scope-related bugs that are common in
C
code that uses lots of global variables.  Years and years ago when I wrote
the first version of PHP I was working for a telco writing software for
a
large telephone switch.  The code was huge and extremely ugly.  Global
variables everywhere.  The team had been chasing a bug for about a week
when I got stubborn and decided it was time to kill the bug.  I printed
out all the source code and laid it out in a long hallway as I crawled
along with different coloured pens and manually traced my way through it
as none of the debuggers we had at the time were of any use.  After
countless hours the bug turned out to be inside a function that silently
modified a global variable which affected another piece of code in a
completely different part of the program.

I swore I would not have the same problem in PHP and thus the requirement
for people to be explicit about using global variables inside functions.
Hopefully it also forces a little bit of structure and organization on
people.

thanks...
now I have an answer I can swallow... cuz I simply didn't get why PHP (which
came from C) had a differente behaviour according to globals.
I never had any problem handling them, but in the other hand I never had
50 of them in a program.
I can understand that making global every single form variable would take
a whole lot of control by the compiler...

I just came with a nice foreach() to make my globals local, and I have to
put them in ALL my functions that handles form vars... I'll consider using
arrays in my next forms

but hey, don't worry... PHP really kicks ASP ass in all matters! :)

cya


. [ Christian Dechery  ]
. Webdeveloper @ T Na Mesa!
. Listmaster @ Gaita-L
. http://www.tanamesa.com.br



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP globals aren't really globals

2001-02-14 Thread Rasmus Lerdorf

  I believe you use globals $var to ACCESS a global variable, not to
  define.

That's correct.  To be perfectly correct here, what you are doing is
creating a reference to the global variable.  Think of it as an alias to
the same variable as the global variable.

  global $foo;

would be equivalent to:

  $foo =  $GLOBALS['foo'];

With the latter giving you the ability to use a different name for the
local reference to the globally-scoped variable.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP globals aren't really globals

2001-02-14 Thread Michael McGlothlin

It's somewhat annoying to have to tell the function which variables are 
global sometimes but overall it makes it easier to avoid stupid 
mistakes. It is a good push to make me less prone to making things 
global. Usually I just avoid using globals and then pack what I do use 
into appropiate arrays and thus save myself most the hassle. In several 
thousand lines of code I may have one or two global vars called.

Boget, Chris wrote:

 Yes.  But with regards to form variables, all you need to do is
 make one variable global:
 $HTTP_POST_VARS
 it is an associative array that contains all the post variables from 
 the form.  Make it global and just loop through it.
 
 exactly, u need to loop to an array to get the globals u want.
 
 
 No, to the the variables/values that you want.
 
 this is not the idea of global, global is global... if it's set outside
 of ALL functions it should be available 'with no extra code' 
 to ALL functions, it works that way in all programming language 
 I'm familiar with... why not in PHP? that's what I wanna know, 
 why globals in PHP doesn't really work like globals?
 
 
 Perhaps I'm missing something.  In order to access the value of any
 variable defined outside the scope of the function, you have to declare
 it as "global".  This is true in every single instance.  If you do not, then
 you cannot access the value of that variable.  While it's been a while
 since I've worked with C, I seem to recall it being the case there as
 well.  And in Pascal.  And in VB.  Again, it's been a while so I could be
 wrong (but don't think so).  
 Also, PHP was written in C.  Why would they institute a behaviour 
 that was radically different than what is part of the parent language?
 
 Chris
 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]