Ответов: 2 Просмотров: 2110
|
Здравствуйте скажите как поправить вот такую вот беду , вот полный текст ошибки Catchable fatal error: Argument 1 passed to RequestRegistry::setRequest() must be an instance of mycontrollers\Request, instance of Request given, called in C:\xampp\htdocs\PhpProject2\mycontrollers\Request.php on line 21 and defined in C:\xampp\htdocs\PhpProject2\RequestRegistry.php on line 46
и дальше сами классы
CODE ( htmlphp):
скопировать код в буфер обмена
include_once 'RequestRegistry.php'; class Request { private $properties; private $feedback = array(); function __construct() { $this->init(); RequestRegistry::setRequest($this); } function init() { if(isset($_SERVER['REQUEST_METHOD'])) { $this->properties = $_REQUEST; return; } foreach ($_SERVER['argv'] as $arg) { { $this->setProperty($key,$val); } } } function getProperty($key){ if(isset($this->properties[$key])) { return $this->properties[$key]; } } function setProperty($key,$val) { $this->properties[$key] = $val; } function addFeedback($msg) { } function getFeedback() { return $this->feedback; } function getFeedBackString($separator="\n") { return implode($separator, $this->feedback); } } require_once 'Registry.php'; class RequestRegistry extends Registry{ private $values =array(); private static $instance; private function __construct() { } static function instance(){ if(!isset(self ::$instance)) { self::$instance = new self(); } return self::$instance; } protected function get($key) { if(isset($this->values[$key])) { return $this->values[$key]; } return null; } protected function set($key, $value) { $this->values[$key] = $value; } static function getRequest() { return self::instance()->get('request'); } static function setRequest(\mycontrollers\Request $request) { return self::instance()->set('request', $request); } }
Я думаю что ошибка возникает изза того что в конструкторе класса Request когда передается этот же объект
(function __construct() {
$this->init();
RequestRegistry::setRequest($this);
}) Request он не создается до конца и соответственно выскакивает ошибка написанная выше. Так ли это или нет и как ее исправить ? |