功能在PHP

时间:2018-04-25 16:13:45

标签: arrays string response jsondecoder

这是类的一部分,试图处理响应内容中的数组和数字,但我遇到了一个问题:



    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 ;
?>
&#13;
&#13;
&#13;

问题是is_jsonable不起作用,当我用字符串值实例化类时,它工作正常 enter image description here

0 个答案:

没有答案