When to use $this->property instead of $property in PHP

前端 未结 5 942
轮回少年
轮回少年 2020-12-18 09:32

Super easy question. Look at the 2 sample class methods.

In the first One I pass in a variable/property call $params I then do $this->params

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 09:47

    You have already answered your question yourself:

    You have to set it like $this->params if you need to access that property in a different method in that class and you can use just $params if you are only using that property in that same method it is in already

提交回复
热议问题