функция не работает в PHP - PullRequest
       8

функция не работает в PHP

0 голосов
/ 25 апреля 2018

это часть класса, пытающаяся обрабатывать массивы и числа в содержимом ответа, но я столкнулся с проблемой:

    public function is_jsonable($content){
        if(is_array($this->content) || is_numeric($this->content)){
            json_decode($this->content,true);
        }
        elseif (null !== $this->$content && !is_string($this->$content) && !is_numeric($this->$content)) {
            throw new Exception('Response Content is Invalid !');
        }
           return $this->content;
     } 

     /**
    * Set Response's content
    *
    * @param string
    *
    */
	function __construct($content = false, $httpCode = 200)
	{
        $this->httpCode = $this->httpStatuses[$httpCode];
		$this->header('content-type', 'text/html');
        $this->content = $content;
	}

	 public function header($name, $value)
    {
        $this->headers[$name] = $value;
        return $this;
    }

    
	 /**
     * Returns the Response as a string
     *
     * @return string 
     * 
     */
   
    public function __toString()
    { 
      if(!headers_sent()){
        	 header("$this->httpProtocole 200 $this->httpCode");
        	 foreach ($this->headers as $name => $value) {
                   header($name.':'.$value,false);      
       }
    }
    return $this->content;
  }

};

и это индекс:

<?php
ini_set('display_errors', 1);

require_once dirname(__DIR__) . '/Core/Http/Response.php';
 
use \Core\Http\Response;

$test = new Response(200); 
echo $test ;
?>

проблема в том, что is_jsonable не работает, он отлично работает, когда я просто создаю экземпляр класса со строковым значением введите описание изображения здесь

...