-1

I get for example name=carl from the url in FooStatic and want to initiate the $Name with Carl so I can use it from another function. Can I do that? Or is there some other better way to do that?

class Foo {

private static $Name = "name";

public static function FooStatic(){

    if (isset($_GET["name"])){
        self::$Name = $_GET["name"];
        return true;
    } else {
        return false;
    }       
}

I am using the name to get more info from another class

public static function getSomething() {
    if (isset($_GET[self::$Name])) {
        $name = $_GET[self::$Name];
        $ret = $someClass->Foo($name);
        return $ret;
    }
}
Fred Wuerges
  • 1,965
  • 2
  • 21
  • 42
e.e
  • 85
  • 2
  • 5
  • Have you tried doing it? – Wayne Whitty Nov 14 '12 at 12:52
  • Please elaborate the question!!! – Vipin Jain Nov 14 '12 at 12:53
  • Semi related: http://stackoverflow.com/questions/11923272/use-global-variables-in-a-class/11923384#11923384 – PeeHaa Nov 14 '12 at 12:54
  • You may be interested by the Symfony2 way to solve this problem. They created "Bag" containers that access elements of an array. You may be inspired by [this class](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/HeaderBag.php) for example. In your constructor, do something like `$this->parameters = $_GET;` and you'll get a beautiful way to do what you want. – Alain Tiemblo Nov 14 '12 at 13:03

1 Answers1

0

The GET-variables are global, so you can always get them from virtually anywhere (if it is in the same span of the execution) if that's what you are asking.

Undrium
  • 2,558
  • 1
  • 16
  • 24