Jump to content

Recommended Posts

Does anyone know how to set static variables from outside a class?

 

i.e.

 

class Example {

   //I want to set a static variable here from outside the class.

   function test(){
   //Then I want to call the variable here. I know that I could include it as a argumennt 
   //in the function call, 
   //but I want to make things easier by using the same static variables for multiple     
   //function calls  
   }
}

$obj = new Example($staticVariable);

if you would read a manual you would know! That same reason applies why you don't get any replies!

 

Here, you get this one for free:

class Example {

    protected static $_var;

    public static function test() {

        if (null === self::$_var) {

            ...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.