2016-02-03 31 views
-2

我不能让它工作,还是我越来越PHP的警告:非法串偏移“脚本”

PHP的警告:非法串偏移“脚本” PHP的警告:非法串偏移“show_type” PHP的警告:非法串偏移 'content_line1'

/** 
    * makeFromRow 
    ******************************************************/ 
    function makeFromRow($row="") { 

     $status = new ItemStatus(); 

     $this->discount_id    = ($row["discount_id"])    ? $row["discount_id"]   : ""; 

     $this->entered     = ($row["entered"])     ? $row["entered"]    : ($this->entered    ? $this->entered    : ""); 
     $this->updated     = ($row["updated"])     ? $row["updated"]    : ($this->updated    ? $this->updated    : ""); 

     $this->id      = ($row["id"])      ? $row["id"]     : ($this->id     ? $this->id      : 0); 
     $this->account_id    = ($row["account_id"])    ? $row["account_id"]   : 0; 
     $this->image_id     = ($row["image_id"])    ? $row["image_id"]    : ($this->image_id    ? $this->image_id    : 0); 
     $this->image_id1    = ($row["image_id1"])    ? $row["image_id1"]    : ($this->image_id1    ? $this->image_id1    : 0); 
     $this->image_id2    = ($row["image_id2"])    ? $row["image_id2"]    : ($this->image_id2    ? $this->image_id2    : 0); 
     $this->image_id3    = ($row["image_id3"])    ? $row["image_id3"]    : ($this->image_id3    ? $this->image_id3    : 0); 
     $this->image_id4    = ($row["image_id4"])    ? $row["image_id4"]    : ($this->image_id4    ? $this->image_id4    : 0); 
     $this->category_id    = ($row["category_id"])    ? $row["category_id"]   : 0; 
     $this->renewal_date    = ($row["renewal_date"])   ? $row["renewal_date"]   : ($this->renewal_date   ? $this->renewal_date   : 0); 
     $this->destination_url   = ($row["destination_url"])   ? $row["destination_url"]  : ""; 
     $this->display_url    = ($row["display_url"])    ? $row["display_url"]   : ""; 
     $this->destination_protocol  = ($row["destination_protocol"]) ? $row["destination_protocol"] : ""; 
     $this->caption     = ($row["caption"])     ? $row["caption"]    : ""; 
     $this->caption1     = ($row["caption1"])    ? $row["caption1"]    : ""; 
     $this->caption2     = ($row["caption2"])    ? $row["caption2"]    : ""; 
     $this->caption3     = ($row["caption3"])    ? $row["caption3"]    : ""; 
     $this->caption4     = ($row["caption4"])    ? $row["caption4"]    : ""; 
     $this->status     = ($row["status"])     ? $row["status"]    : ($this->status    ? $this->status     : $status->getDefaultStatus()); 
     $this->type      = ($row["type"])     ? $row["type"]     : ($this->type     ? $this->type     : 0); 
     $this->section     = ($row["section"])     ? $row["section"]    : ($this->section    ? $this->section    : "general"); 
     $this->target_window   = ($row["target_window"])   ? $row["target_window"]   : 2; 
     $this->content_line1   = ($row["content_line1"])   ? $row["content_line1"]   : ""; 
     $this->content_line11   = ($row["content_line11"])   ? $row["content_line11"]  : ""; 
     $this->content_line12   = ($row["content_line12"])   ? $row["content_line12"]  : ""; 
     $this->content_line13   = ($row["content_line13"])   ? $row["content_line13"]  : ""; 
     $this->content_line14   = ($row["content_line14"])   ? $row["content_line14"]  : ""; 
     $this->content_line2   = ($row["content_line2"])   ? $row["content_line2"]   : ""; 
     $this->content_line21   = ($row["content_line21"])   ? $row["content_line21"]  : ""; 
     $this->content_line22   = ($row["content_line22"])   ? $row["content_line22"]  : ""; 
     $this->content_line23   = ($row["content_line23"])   ? $row["content_line23"]  : ""; 
     $this->content_line24   = ($row["content_line24"])   ? $row["content_line24"]  : ""; 
     $this->unpaid_impressions  = ($row["unpaid_impressions"])  ? $row["unpaid_impressions"] : ($this->unpaid_impressions ? $this->unpaid_impressions  : 0); 
     $this->impressions    = ($row["impressions"])    ? $row["impressions"]   : ($this->impressions   ? $this->impressions   : 0); 
     $this->unlimited_impressions = ($row["unlimited_impressions"]) ? $row["unlimited_impressions"] : ($this->unlimited_impressions ? $this->unlimited_impressions : "n"); 
     $this->expiration_setting  = ($row["expiration_setting"])  ? $row["expiration_setting"] : 0; 
     $this->show_type    = ($row["show_type"])    ? $row["show_type"]    : 0; 
     $this->script     = ($row["script"])     ? $row["script"]    : ""; 

    } 

    /** 
    * Save 
    ******************************************************/ 
+0

这意味着'$行[ “脚本”]'是不确定的。而不是'($ row [“script”])',为你的检查做'empty($ row [“script”])''。请注意,'0','NULL','[]'等计算为“空”,因此请确保在这些值有效的情况下进行计数。 – jperezov

+0

你的意思是? $ this-> script = empty($ row [“script”])? $ row [“script”]:“”; –

+0

是的。就是这样。 – jperezov

回答

0

您可以添加isset函数总是:

例如替换所有$row[

... 
$this->show_type = ($row["show_type"]) ? $row["show_type"]: 0; 
... 

到:

... 
$this->show_type = (isset($row["show_type"])) ? $row["show_type"]: 0; 
... 
相关问题