Re: A Newbie needs help with his first Class

From: Date: Fri, 22 Mar 2002 14:57:18 +0000
Subject: Re: A Newbie needs help with his first Class
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-89691@lists.php.net to get a copy of this message
$DOCUMENT_ROOT inside a function, scope problems. Pass it as an argument or global, or use $_SERVER['DOCUMENT_ROOT']; -- Julio Nobrega. Um dia eu chego lá: http://sourceforge.net/projects/toca Ajudei? Salvei? Que tal um presentinho? http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884 "Don" <mail4donpro@rogers.com> wrote in message news:000f01c1d1a1$9105c9a0$4fad2b18@ym.phub.net.cable.rogers.com... Hi, I'm trying to write my first class. Here is the code contained in a file called "globals.php": <?PHP class Globals { var $gDISPLAY = 1; /* Display graphic - no rollover */ var $gROLLOVER = 2; /* Display graphic with rollover */ var $root_path; /* Path to document root directory */ var $relative_path; /* Path from document root to relative root directory */ function Globals($start_dir) { if ( strlen($DOCUMENT_ROOT) == 0) { $this->$root_path = "/"; } else { $this->$root_path = $DOCUMENT_ROOT; } $this->$relative_path = $this->$root_path . $start_dir; } } $global = new Globals("/staging_area/phase-2/"); ?> Within my html page, I am tesing the class by trying the following: <?php require("globals.php"); echo $global->root_path . "<br>"; echo $global->relative_path . "<br>"; ?> However, nothing is being written to my browser. Is there a problem with the code? Thanks,. Don

« previous php.general (#89691) next »