Page 1 of 1

$_SERVER in a class

Posted: Thu Dec 28, 2006 2:27 pm
by orbstra
How would I use $_SERVER in a class? I am getting an error in my IDE

Posted: Thu Dec 28, 2006 2:31 pm
by Luke
please be more specific... maybe post some code

Posted: Thu Dec 28, 2006 2:31 pm
by John Cartwright
there is nothing wrong with using $_SERVER in a class, it is a super global. Are you sure you've typed everything correctly?

Post some code.

Posted: Thu Dec 28, 2006 2:34 pm
by orbstra

Code: Select all

var $request = $_SERVER['REQUEST_URI']; //Gets Full URL
		var $dirs = parse_url($request, PHP_URL_PATH); //Gets all URL Dirs
		var $url = explode("/", $dirs); //Puts URL Dirs into array $url
'missing ; after decloration....'
'parse error } at end of class statement...' a bunch of those, although I have combed through my code and I can't find a single decimal out of place

Posted: Thu Dec 28, 2006 2:36 pm
by thomas777neo
You should be able to use it anywhere as it is a global variable.

Perhaps post some code that you can be assisted further

Posted: Thu Dec 28, 2006 2:36 pm
by John Cartwright
you cannot reference functions or variables in var's.. you may only assign it a default string, null, or numeric value.

What your wanting to do belongs in separate methods or the constructor.

Posted: Thu Dec 28, 2006 2:39 pm
by orbstra
thomas777neo wrote:You should be able to use it anywhere as it is a global variable.

Perhaps post some code that you can be assisted further

Code: Select all

class guav_engine
	{
		var $url;
		var $method;
		//Get the URL
		var $request = $_SERVER['REQUEST_URI']; //Gets Full URL
		var $dirs = parse_url($request, PHP_URL_PATH); //Gets all URL Dirs
		var $url = explode("/", $dirs); //Puts URL Dirs into array $url
		
		function guav_sys_method_get() //Split $method from $url
			{
				global $method, $url;
				m_catch(admin, admin);
				m_catch(home, sys);
				m_catch(blog, sys);
				m_catch(null, sys);
				m_catch(page, page);
				return $method;
			}
		
		$max = count($url); //Split the $dir from $url
		for ($i=1;$i==$max;$i++)
			{
				$dir[$i-1] = $url[$i];
			}

PS: just learned classes about 5 minutes ago, so super hard-core technical answers will prob confuse me.
thnx all

Posted: Thu Dec 28, 2006 2:42 pm
by John Cartwright
I've already answered your question.

Posted: Thu Dec 28, 2006 2:44 pm
by orbstra
Jcart wrote:I've already answered your question.
How do I put it in a different method or constructor?

Posted: Thu Dec 28, 2006 2:49 pm
by Kieran Huggins
php4 http://www.php.net/manual/en/language.o ... ructor.php

php5 http://www.php.net/manual/en/language.oop5.decon.php

php5 example:

Code: Select all

class guav_engine
        {
                var $url;
                var $method;

                var $request;
                var $dirs;
                var $url;

                function __construct()
                       {
                                //Get the URL
                                $this->request = $_SERVER['REQUEST_URI']; //Gets Full URL
                                $this->dirs = parse_url($request, PHP_URL_PATH); //Gets all URL Dirs
                                $this->url = explode("/", $dirs); //Puts URL Dirs into array $url
                }
               
                function guav_sys_method_get() //Split $method from $url
                        {
                                global $method, $url;
                                m_catch(admin, admin);
                                m_catch(home, sys);
                                m_catch(blog, sys);
                                m_catch(null, sys);
                                m_catch(page, page);
                                return $method;
                        }
               
                $max = count($url); //Split the $dir from $url
                for ($i=1;$i==$max;$i++)
                        {
                                $dir[$i-1] = $url[$i];
                        }
//....

Posted: Thu Dec 28, 2006 2:50 pm
by John Cartwright
i'll assume your using php4

Code: Select all

class foobar
{
   var $request;
   var $dirs;

   function foobar()
   {
      $this->request = $_SERVER['REQUEST_URI'];
      $this->dirs = parse_url($this->request, PHP_URL_PATH);

      //...
   }
}

Posted: Thu Dec 28, 2006 3:21 pm
by orbstra
oh man i love you guys