M
M
MaximMRX2017-04-07 11:58:43
PHP
MaximMRX, 2017-04-07 11:58:43

Template Registry OOP?

Good day. Started learning OOP. The question arose:
There is a class APP, it just has a static $App container that returns objects of the Registry class.
You have to contact from the controller like this

use vendor\core\App;

App::$App->NameClass->getUser();

Question. How do I get rid of the $App container so that I can call the registry plugins like this:
use vendor\core\App;

App::NameClass->getUser();
// или вот так
use vendor\core\App;

App->NameClass->getUser();

App class code
<?php
  namespace vendor\core;

  use vendor\core\Registry;

  class App {
    public static $App;

    public function __construct(){
      self::$App = Registry::instance();
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-04-07
@GM_pAnda

How do I get rid of the $App container so that I can call the registry plugins like this:

The main question is why? Your $app class is a variation on a singleton (albeit a rather kinky one) to avoid duplicates of the Registry object with all its contents in this situation.
So you won’t do it at all, there are either static methods that can be called without creating an object, or ordinary methods for which you need to create an object. And you ask how to call a regular method without creating a class, the answer is no way.
If you want to get rid of the App class - then create a Registry object and use it (although this is not a good idea)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question