English 中文(简体)
我一再宣布同样情况。
原标题:var s I keep declaring the same things over again

如果我不敢做我想要的事情,我基本上需要在全球范围内储存以下信息,如果有人要求的话,那么他们就能够摆脱任何公共职能,而不必重新适应目前需要信息的职能。

public function savenewbusinesslead($tradingname, $companyname)
{
    $this->tradingname  = $tradingname;
    $this->companyname  = $companyname;
}

public function sendemail($email,$tradingname){
    $this->email = $email;
    $this->tradingname = $tradingname
}

我想做的是:

private function global($tradingname, $companyname){
     $this->tradingname = $tradingname;
     $this->companyname = $companyname;
}
public function savenewbusinesslead(){
     print $this->global->tradingname;
}
最佳回答

为了在你的方法范围内提及全球变量,你需要使用全球关键词,如:

  //assuming $tradingname is defined ouside your method
public function savenewbusinesslead(){
   global $tradingname;
   print $tradingname;
}

这是否有助于?

问题回答

You can always use a static variable in your class to handle this.

http://www.php.net/manual/en/language.oop5.static.php rel=“nofollow”http://www.php.net/manual/en/English.oop5.static.php





相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签