Use global variables in a class

前端 未结 4 1765
日久生厌
日久生厌 2020-11-22 13:36

I\'m trying to create a pagination class and use a variable from outside the class.

But it\'s giving me the fatal error \"Call to a member function query() on a non-

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 13:49

    The other answers thus far are definitely preferable to using a global since that will ruin your encapsulation (eg you'd need to have that object defined prior to calling that method).

    It's much better to enforce that in the method signature or not use a class.

提交回复
热议问题