我不断地重复声明同样的事情

发布于 2024-12-08 05:03:04 字数 667 浏览 0 评论 0原文

不确定是否有办法做我想做的事情,我基本上需要将以下信息存储在全局变量中,如果请求它们,则能够从任何公共函数中获取它们,而不必将其重新发送到当前需要信息的功能我正在执行以下操作

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;
}

Not sure if there is away to do what I want, I basically need to store the following information in a global var, and if they are being requested, then be able to fetch them from any public function without having to re-send it to the function that needs the information at current I am doing the following

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

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

What I want to do is the following

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久而酒知 2024-12-15 05:03:04

要从方法中引用全局变量,您需要使用 global 关键字,如下所示:

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

这有帮助吗?

To reference a global variable from within your methods, you need to use the global keyword, like this:

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

Does this help?

暮年 2024-12-15 05:03:04

您始终可以在类中使用静态变量来处理此问题。

更多信息: http://www.php.net/manual/en /语言.oop5.static.php

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

More over there: http://www.php.net/manual/en/language.oop5.static.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文