如何在创建类实例时动态设置公共变量

When I initialize a new class instance I want to set a public variable based on the current url.

How do I go about setting the public variable dynamically when the class instance is created so it is available without having to call a function.

 class CONFIGURATOR{
    static public $ACTIVE = true;
    public $CURRENT_URL="<current_url here>"
  }

Use the constructor :

class CONFIGURATOR{
   static public $ACTIVE = true;
   public $CURRENT_URL="<current_url here>"

   public function __construct($url)
   {
       $this->CURRENT_URL = $url;
   }
}

You can call your object like this :

$configurator = new CONFIGURATOR($your_url);

Use constructor , it may be solve your problem

class CONFIGURATOR{
    static public $ACTIVE = true;
    public $CURRENT_URL="";

    function __construct()
    {
        $this->$CURRENT_URL="<current_url here>";
    }
  }

Thank You