我不断地重复声明同样的事情
不确定是否有办法做我想做的事情,我基本上需要将以下信息存储在全局变量中,如果请求它们,则能够从任何公共函数中获取它们,而不必将其重新发送到当前需要信息的功能我正在执行以下操作
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要从方法中引用全局变量,您需要使用 global 关键字,如下所示:
这有帮助吗?
To reference a global variable from within your methods, you need to use the global keyword, like this:
Does this help?
您始终可以在类中使用静态变量来处理此问题。
更多信息: 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