[PHP] Predefined Variables In Classes

2003-01-26 Thread @ Nilaab
Hello Everyone,

I am a little confused. Why do predefined variables like $PHP_SELF or
$DOCUMENT_ROOT not process within a class, in the methods secifically. For
example:

?php
class someClass {

   function someFunction () {
$root = $DOCUMENT_ROOT;
return $root;
   }

   function someFunction2 () {
$path = $this-someFunction() . $PHP_SELF;
return $path;
   }
}
?

I just threw this together to give you an example of how I might be using
these two predefined variables in a class. The problem is that
$DOCUMENT_ROOT or $PHP_SELF won't parse or something. It just returns blank.

It is included in another page when needed, say somePage.php. Shouldn't
$PHP_SELF recognize the somePage.php as the current running script file, as
opposed to the class file where these two functions are called? If it
doesn't work that way then how do I do this without sending predefined
variable parameters to these functions?

Please note that register globals is on. I could not find any documentation
on this on php.net. Maybe someone can give me a hint of point it out for me
on the documentation. Thanks.


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




Re: [PHP] Predefined Variables In Classes

2003-01-26 Thread Philip Olson

Read:
  http://www.php.net/variables.scope

Also note that $_SERVER is an autoglobal.

Regards,
Philip


On Sun, 26 Jan 2003, @ Nilaab wrote:

 Hello Everyone,
 
 I am a little confused. Why do predefined variables like $PHP_SELF or
 $DOCUMENT_ROOT not process within a class, in the methods secifically. For
 example:
 
 ?php
 class someClass {
 
function someFunction () {
   $root = $DOCUMENT_ROOT;
   return $root;
}
 
function someFunction2 () {
   $path = $this-someFunction() . $PHP_SELF;
   return $path;
}
 }
 ?
 
 I just threw this together to give you an example of how I might be using
 these two predefined variables in a class. The problem is that
 $DOCUMENT_ROOT or $PHP_SELF won't parse or something. It just returns blank.
 
 It is included in another page when needed, say somePage.php. Shouldn't
 $PHP_SELF recognize the somePage.php as the current running script file, as
 opposed to the class file where these two functions are called? If it
 doesn't work that way then how do I do this without sending predefined
 variable parameters to these functions?
 
 Please note that register globals is on. I could not find any documentation
 on this on php.net. Maybe someone can give me a hint of point it out for me
 on the documentation. Thanks.
 
 
 -- 
 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] Predefined Variables In Classes

2003-01-26 Thread @ Nilaab
Well, I don't think this has anything to do with predefined variables being
global or not because I only have use for them within the specific methods.
The methods will capture their values and assign them to a variable inside
the function, which will return that variable at the end. The processing of
$PHP_SELF and $DOCUMENT_ROOT only happens in one place. I might be wrong,
not sure. But right now all I know is that I am confused and the link you
sent me didn't help explain what I need to know because it states no mention
of predefined variables. Can you perhaps give me an example of what you are
trying to tell me?

I read about variable scope and it says nothing about predefined variables.
So how will using the $_SERVER associate array help me with this? Remember
that globals is on, so I don't need to use $_SERVER, $_POST, $_GET, etc. to
get my values. But, in the meantime I'll go ahead and try using the
associate autoglobal arrays anyway, like $_SERVER, just to test it and to
see if it works for me. And if it does, it'll bug me until I find out why it
works. Thanks your input Philip. If anyone else has any thoughts or
explainations for me to understad this then that would be great.


Read:
  http://www.php.net/variables.scope

Also note that $_SERVER is an autoglobal.

Regards,
Philip

 -Original Message-
 From: @ Nilaab [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, January 26, 2003 1:46 PM
 To: Php-General
 Subject: [PHP] Predefined Variables In Classes


 Hello Everyone,

 I am a little confused. Why do predefined variables like $PHP_SELF or
 $DOCUMENT_ROOT not process within a class, in the methods secifically. For
 example:

 ?php
 class someClass {

function someFunction () {
   $root = $DOCUMENT_ROOT;
   return $root;
}

function someFunction2 () {
   $path = $this-someFunction() . $PHP_SELF;
   return $path;
}
 }
 ?

 I just threw this together to give you an example of how I might be using
 these two predefined variables in a class. The problem is that
 $DOCUMENT_ROOT or $PHP_SELF won't parse or something. It just
 returns blank.

 It is included in another page when needed, say somePage.php. Shouldn't
 $PHP_SELF recognize the somePage.php as the current running
 script file, as
 opposed to the class file where these two functions are called? If it
 doesn't work that way then how do I do this without sending predefined
 variable parameters to these functions?

 Please note that register globals is on. I could not find any
 documentation
 on this on php.net. Maybe someone can give me a hint of point it
 out for me
 on the documentation. Thanks.


 --
 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] Predefined Variables In Classes

2003-01-26 Thread John W. Holmes
 Well, I don't think this has anything to do with predefined variables
 being
 global or not because I only have use for them within the specific
 methods.
 The methods will capture their values and assign them to a variable
inside
 the function, which will return that variable at the end. The
processing
 of
 $PHP_SELF and $DOCUMENT_ROOT only happens in one place. I might be
wrong,
 not sure. But right now all I know is that I am confused and the link
you
 sent me didn't help explain what I need to know because it states no
 mention
 of predefined variables. Can you perhaps give me an example of what
you
 are
 trying to tell me?

Predefined or not, it's still a variable. If you want a variable inside
of your function to have the value of a variable outside of your
function, then you have to make it global. $PHP_SELF inside of your
function has no value because it's relative to the function, not the
script. Just like $a inside of a function wouldn't have a value unless
you assigned one to it. Using global $PHP_SELF at the beginning of
your function (or method, same thing) will now make the variable
$PHP_SELF have the same value as it does outside of your function.
 
 I read about variable scope and it says nothing about predefined
 variables.
 So how will using the $_SERVER associate array help me with this?
Remember
 that globals is on, so I don't need to use $_SERVER, $_POST, $_GET,
etc.
 to
 get my values. But, in the meantime I'll go ahead and try using the
 associate autoglobal arrays anyway, like $_SERVER, just to test it and
to
 see if it works for me. And if it does, it'll bug me until I find out
why
 it
 works. Thanks your input Philip. If anyone else has any thoughts or
 explainations for me to understad this then that would be great.

$_SERVER['PHP_SELF'] will always work, regardless of variable scope or
register_globals setting. The $_SERVER array is a superglobal, so it'll
have the same value inside your method or outside of it, without you
having to do anything special. 

Hope that helps.

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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




RE: [PHP] Predefined Variables In Classes

2003-01-26 Thread @ Nilaab
John,

YES! That's what I was looking for. Thanks for the explaination. It helps a
great deal. I had $_SERVER['DOCUMENT_ROOT'] work for me. But I'm still
struggling with $_SERVER['PHP_SELF'], because it's not returning anything.

So here's the second part to my question stated earlier. Let's say, for
example, I had a class included in someFile.php. The included class looks
like the class below:

?php
class someClass {

   function someFunction () {
$root = $_SERVER['DOCUMENT_ROOT'];
return $root;
   }

   function someFunction2 () {
$path = $this-someFunction() . $_SERVER['PHP_SELF'];
return $path;
   }
}
?

Shouldn't the value of $_SERVER['PHP_SELF'] contain the path of someFile.php
and not the path of the class file which was included in someFile.php? Or
what should this value be? I want the $_SERVER['PHP_SELF'] value to be
/path/someFile.php, or the value of whatever page included this class file
and called the methods of the class. How would I do that? Because right now
it returns a blank string.



 -Original Message-
 From: John W. Holmes [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, January 26, 2003 3:37 PM
 To: '@ Nilaab'; 'Php-General'
 Subject: RE: [PHP] Predefined Variables In Classes


  Well, I don't think this has anything to do with predefined variables
  being
  global or not because I only have use for them within the specific
  methods.
  The methods will capture their values and assign them to a variable
 inside
  the function, which will return that variable at the end. The
 processing
  of
  $PHP_SELF and $DOCUMENT_ROOT only happens in one place. I might be
 wrong,
  not sure. But right now all I know is that I am confused and the link
 you
  sent me didn't help explain what I need to know because it states no
  mention
  of predefined variables. Can you perhaps give me an example of what
 you
  are
  trying to tell me?

 Predefined or not, it's still a variable. If you want a variable inside
 of your function to have the value of a variable outside of your
 function, then you have to make it global. $PHP_SELF inside of your
 function has no value because it's relative to the function, not the
 script. Just like $a inside of a function wouldn't have a value unless
 you assigned one to it. Using global $PHP_SELF at the beginning of
 your function (or method, same thing) will now make the variable
 $PHP_SELF have the same value as it does outside of your function.

  I read about variable scope and it says nothing about predefined
  variables.
  So how will using the $_SERVER associate array help me with this?
 Remember
  that globals is on, so I don't need to use $_SERVER, $_POST, $_GET,
 etc.
  to
  get my values. But, in the meantime I'll go ahead and try using the
  associate autoglobal arrays anyway, like $_SERVER, just to test it and
 to
  see if it works for me. And if it does, it'll bug me until I find out
 why
  it
  works. Thanks your input Philip. If anyone else has any thoughts or
  explainations for me to understad this then that would be great.

 $_SERVER['PHP_SELF'] will always work, regardless of variable scope or
 register_globals setting. The $_SERVER array is a superglobal, so it'll
 have the same value inside your method or outside of it, without you
 having to do anything special.

 Hope that helps.

 ---John W. Holmes...

 PHP Architect - A monthly magazine for PHP Professionals. Get your copy
 today. http://www.phparch.com/



 --
 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] Predefined Variables In Classes

2003-01-26 Thread @ Nilaab
Nevermind John, it worked! I had $_SERVER['PHP_SELF'] spelled as
$SERVER['PHP_SELF']. I appreciate your help!  :P

 -Original Message-
 From: @ Nilaab [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, January 26, 2003 4:01 PM
 To: Php-General
 Subject: RE: [PHP] Predefined Variables In Classes


 John,

 YES! That's what I was looking for. Thanks for the explaination.
 It helps a
 great deal. I had $_SERVER['DOCUMENT_ROOT'] work for me. But I'm still
 struggling with $_SERVER['PHP_SELF'], because it's not returning anything.

 So here's the second part to my question stated earlier. Let's say, for
 example, I had a class included in someFile.php. The included class looks
 like the class below:

 ?php
 class someClass {

function someFunction () {
   $root = $_SERVER['DOCUMENT_ROOT'];
   return $root;
}

function someFunction2 () {
   $path = $this-someFunction() . $_SERVER['PHP_SELF'];
   return $path;
}
 }
 ?

 Shouldn't the value of $_SERVER['PHP_SELF'] contain the path of
 someFile.php
 and not the path of the class file which was included in someFile.php? Or
 what should this value be? I want the $_SERVER['PHP_SELF'] value to be
 /path/someFile.php, or the value of whatever page included this class file
 and called the methods of the class. How would I do that? Because
 right now
 it returns a blank string.



  -Original Message-
  From: John W. Holmes [mailto:[EMAIL PROTECTED]]
  Sent: Sunday, January 26, 2003 3:37 PM
  To: '@ Nilaab'; 'Php-General'
  Subject: RE: [PHP] Predefined Variables In Classes
 
 
   Well, I don't think this has anything to do with predefined variables
   being
   global or not because I only have use for them within the specific
   methods.
   The methods will capture their values and assign them to a variable
  inside
   the function, which will return that variable at the end. The
  processing
   of
   $PHP_SELF and $DOCUMENT_ROOT only happens in one place. I might be
  wrong,
   not sure. But right now all I know is that I am confused and the link
  you
   sent me didn't help explain what I need to know because it states no
   mention
   of predefined variables. Can you perhaps give me an example of what
  you
   are
   trying to tell me?
 
  Predefined or not, it's still a variable. If you want a variable inside
  of your function to have the value of a variable outside of your
  function, then you have to make it global. $PHP_SELF inside of your
  function has no value because it's relative to the function, not the
  script. Just like $a inside of a function wouldn't have a value unless
  you assigned one to it. Using global $PHP_SELF at the beginning of
  your function (or method, same thing) will now make the variable
  $PHP_SELF have the same value as it does outside of your function.
 
   I read about variable scope and it says nothing about predefined
   variables.
   So how will using the $_SERVER associate array help me with this?
  Remember
   that globals is on, so I don't need to use $_SERVER, $_POST, $_GET,
  etc.
   to
   get my values. But, in the meantime I'll go ahead and try using the
   associate autoglobal arrays anyway, like $_SERVER, just to test it and
  to
   see if it works for me. And if it does, it'll bug me until I find out
  why
   it
   works. Thanks your input Philip. If anyone else has any thoughts or
   explainations for me to understad this then that would be great.
 
  $_SERVER['PHP_SELF'] will always work, regardless of variable scope or
  register_globals setting. The $_SERVER array is a superglobal, so it'll
  have the same value inside your method or outside of it, without you
  having to do anything special.
 
  Hope that helps.
 
  ---John W. Holmes...
 
  PHP Architect - A monthly magazine for PHP Professionals. Get your copy
  today. http://www.phparch.com/
 
 
 
  --
  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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php