How to pass Global variables to classes in PHP?

后端 未结 5 1593
终归单人心
终归单人心 2021-01-05 02:41

How can I pass the global variables to the classes I want to use without declare them as GLOBAL in every method of the class ?

example :

$admin = \"         


        
5条回答
  •  灰色年华
    2021-01-05 03:11

    Try passing the variable that you want to be global to the object as an argument, and then use the __constructor() method to make it a class property.

    You can find more info and examples here: In php when initializing a class how would one pass a variable to that class to be used in its functions?

提交回复
热议问题