Global variable inside a constructor with PHP

前端 未结 3 1517
情话喂你
情话喂你 2021-01-18 10:50

This should be obvious, but I\'m getting a bit confused about PHP variable scope.

I have a variable inside a Constructor, which I want to use later in a function in

3条回答
  •  礼貌的吻别
    2021-01-18 11:19

    Globals are considered harmful. If this is an outside dependency, pass it through the constructor and save it inside a property for later use. If you need this to be set only during the call to test, you might want to consider making it an argument to that method.

提交回复
热议问题