PHP class: Global variable as property in class

后端 未结 7 1117
囚心锁ツ
囚心锁ツ 2020-12-05 13:03

I have a global variable outside my class = $MyNumber;


How do I declare this as a property in myClass?
For every method in my class, this is what

相关标签:
7条回答
  • 2020-12-05 13:53

    class myClass { protected $foo;

    public function __construct(&$var)
    {
        $this->foo = &$var;
    }
    
    public function foo()
    {
        return ++$this->foo;
    }
    

    }

    0 讨论(0)
提交回复
热议问题