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

From: Date: Thu, 10 May 2007 14:09:31 +0000
Subject: Re: One class, many methods: PHP4.x: Q's
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-254728@lists.php.net to get a copy of this message
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"

« previous php.general (#254728) next »