Overhead of a global php variable under

I am currently developing a framework that uses a class object Core(this class has great functionality and makes the work environment). The structure corresponds to the MVC architecture and has loosely coupled Model, Control, View classes. Abstract classes require a reference to the class Core. What I have done so far: creating a single class object Coreand referencing it using the PHP keyword globalin the Model, Control, View classes.

I do not like this approach because:

  • This path is not an object oriented way in my sense
  • The IDE (netbeans) cannot provide documentation to the class object Core- a pain for developers who will use this infrastructure.
  • I'm really worried about performance issues - I don't know, slower or less global.

I searched and found no information about the performance issue. I also searched for stackoverflow and found Does global creation use any overhead? and Advantage / disadvantage between global variables and function parameters in PHP? etc., but they do not contain much information. My main concern right now is performance , so please help.

+5
source share
3 answers

NevilleK, Core` God Object antipattern.

, , /, . , .

- ( php ), .

. , Core .


:

+4

-, , http://en.wikipedia.org/wiki/God_object - "" " ", -.

- - . , , ; , . JMeter " " , . , , Qaru .

In general, I would say that having a global class should not have a big impact on performance unless it does a lot of work. Just loading the class into memory, parsing it, etc. It affects performance - but it is unlikely to be noticeably slower than any other routes that you could take.

If, however, your “main” class executes a lot of initialization logic when accessing the page, this will obviously affect performance.

+1
source

All Articles