За последние 24 часа нас посетили 21940 программистов и 1009 роботов. Сейчас ищут 634 программиста ...

Что такое ?? в PHP ?

Тема в разделе "PHP для новичков", создана пользователем SpikePHP, 7 июн 2019.

  1. SpikePHP

    SpikePHP Активный пользователь

    С нами с:
    6 май 2015
    Сообщения:
    130
    Симпатии:
    23
    Здравствуйте)
    Ковыряю одного товарища тестовое задание - простенькое MVC приложение без фреймворков. И там вижу вот такую строчку :
    PHP:
    1.             $this->controller = ucfirst($url[0]) ?? 'Application';
    Оно на 80-й строке в файле ниже. Что это такое? Может там ошибка? Если ошибка, то что там должно быть?
    сам файл вот :
    PHP:
    1. <?php
    2.  
    3. namespace Core;
    4.  
    5. use \Application\Controller\ErrorController;
    6.  
    7. class Application
    8. {
    9.     /**
    10.      * @var array
    11.      */
    12.     protected $config;
    13.  
    14.     /**
    15.      * @var string
    16.      */
    17.     private $controller;
    18.  
    19.     /**
    20.      * @var string
    21.      */
    22.     private $action = null;
    23.  
    24.     /**
    25.      * @var array
    26.      */
    27.     private $params = array();
    28.  
    29.     /**
    30.      * Class construct
    31.      * @param array $config
    32.      */
    33.     public function __construct(array $config = null)
    34.     {
    35.         $this->config = $config;
    36.  
    37.         $this->splitUrl();
    38.         $this->config['module'] = $this->controller;
    39.  
    40.         $fileController = '../module/' . ucfirst($this->controller) . '/Controller/' .
    41.             ucfirst($this->controller) . 'Controller.php';
    42.         $classController = ucfirst($this->controller) . '\\Controller\\' . ucfirst($this->controller) . 'Controller';
    43.  
    44.         if (!$this->controller) {
    45.             $page = new ApplicationController($this->config);
    46.             $page->listAction();
    47.         } elseif (file_exists($fileController)) {
    48.             $controller = new $classController($this->config);
    49.  
    50.             if (method_exists($controller, $this->action) && is_callable(array($controller, $this->action))) {
    51.                 if (!empty($this->params)) {
    52.                     call_user_func_array(array($controller, $this->action), $this->params);
    53.                 } else {
    54.                     $controller->{$this->action}(null);
    55.                 }
    56.             } elseif (strlen($this->action) == 0) {
    57.                 $this->config['module'] = 'Application';
    58.                 $controller->indexAction();
    59.             } else {
    60.                 $this->config['module'] = 'Application';
    61.                 $page = new ErrorController($this->config);
    62.                 $page->errorAction();
    63.             }
    64.         } else {
    65.             $this->config['module'] = 'Application';
    66.             $page = new ErrorController($this->config);
    67.             $page->errorAction();
    68.         }
    69.     }
    70.  
    71.     /**
    72.      * Get and split the URL
    73.      */
    74.     private function splitUrl()
    75.     {
    76.         $this->controller = 'Application';
    77.         if (isset($_GET['url'])) {
    78.             $url = explode('/',filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
    79.  
    80.             $this->controller = ucfirst($url[0]) ?? 'Application';
    81.             $this->action     = isset($url[1]) ? $url[1] . 'Action' : null;
    82.  
    83.             // Remove controller and action from the split URL
    84.             unset($url[0], $url[1]);
    85.  
    86.             $this->params = array_values($url);
    87.         }
    88.     }
    89. }
     
    AlexandrS нравится это.
  2. romach

    romach Старожил

    С нами с:
    26 окт 2013
    Сообщения:
    2.904
    Симпатии:
    719
    AlexandrS и SpikePHP нравится это.
  3. MouseZver

    MouseZver Суперстар

    С нами с:
    1 апр 2013
    Сообщения:
    7.748
    Симпатии:
    1.321
    Адрес:
    Лень
    вообще не правильно, нужно так :
    PHP:
    1. ucfirst ( $url[0] ?? 'Application' );
     
    SpikePHP нравится это.