简体   繁体   中英

Share values between to static function with our pass through arguments

I want to share a object between two static functions in a class with out pass through parameters. for example in my class have to static function ProfileRegistration() it get a object through parameter and I want to call another function Format() it process the same object. I want to call the Format() function without passing the object once again

I don't know share the value between to function, so I Pass it as a parameter. How to avoid it?

class SMSList {

     var $objLogin;

     public function __construct()

     {


     }

     public static  function ProfileRegistration($objLogin)
     {

         $objself=new self();
         $objself->objLogin=$objLogin;

         $obj=new SMSMessage();

         if($obj->profile_registration_sms_status==1)
         {
             $msg=self::Format($obj->profile_registration_sms,$objself-objLogin);

         return SMS::sendSMS($objself->objLogin->mobile,$msg);
         }
     }

     public  function Format($message,$objLogin)

     {
         $message=str_replace('#NAME#',$objLogin->contact_person,$message);
         $message=str_replace('#COMP_NAME#',$objLogin->companyname,$message );
         $message=str_replace('#MOBILE#',$objLogin->mobile,$message);
         $message=str_replace('#CITY#',$objLogin->city,$message);
         $message=str_replace('#EMAILID#',$objLogin->emailid,$message);
         return $message;
     }

}

Solve this problem using static variable. code example here

class SMSList {
    public static $objLogin;
    public function __construct()
    {

    }

    public static  function ProfileRegistration($objLogin)
    {

        self::$objLogin=$objLogin;
        $obj=new SMSMessage();

        if($obj->profile_registration_sms_status==1)
        {
            $msg=self::Format($obj->profile_registration_sms);

            return SMS::sendSMS( self::$objLogin->mobile,$msg);
        }
    } public  function Format($message)
    {
        $message=str_replace('#NAME#',self::$objLogin->contact_person,$message);
        $message=str_replace('#COMP_NAME#',self::$objLogin->companyname,$message );
        $message=str_replace('#MOBILE#',self::$objLogin->mobile,$message);
        $message=str_replace('#CITY#',self::$objLogin->city,$message);
        $message=str_replace('#EMAILID#',self::$objLogin->emailid,$message);
        return $message;
    }


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM