Re: One class, many methods: PHP4.x: Q's

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Micky Hulse wrote:

I have a class called Randimg. Within that class, I have several methods. Within a few of those methods, I use the below code snippet:

$_SERVER['DOCUMENT_ROOT']

What would be the best way to assign the above code to a global variable/constant within the class?

Within the constructor for Randimg you could set a local protected variable:

class Randimg
{
  var $docroot = false;

  function Randimg ()
  {
    $this->docroot = $_SERVER['DOCUMENT_ROOT'];
  }

and then you can just reference $this->docroot from any of the Randimg methods.

In PHP 5 could you create $docroot as a protected class constant, but in PHP 4 the above will have to do.

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux