Correcting a Illegal String Offset warning in WordPress Plugin

大憨熊 提交于 2021-02-11 18:22:04

问题


I am receiving this error "Warning: Illegal string offset 'width' in contact-me.php on line 250

Warning: Illegal string offset 'title' in contact-me.php on line 252"

and I realized this section of code in the file is wrong, however I'm not quite adept in PHP yet and I am wondering if someone can help me re-write this section to eliminate the error. Thanks! (the error starts on line 250 which begins with $width below and also line 252 which begins with $title).

I tried implementing some of the corrections on other threads but was unsuccessful. I appreciate your assistance.

function shortcode_handler($_atts) {
    if ($this->check_settings() === true) {
        $width = intval($_atts["width"]);
        if ($width < 100 || $width > 1000) $width = "";
        $title = $_atts["title"];
        if (empty($title)) $title = htmlspecialchars($this->options['form_title'], ENT_QUOTES);
        $suffix = "_".rand(1000, 9999);
        $form = '

I solved it. I used the following code:

if (isset($_atts["width"]))
        $width = var_dump($_atts["width"]);           
  if (isset($_atts["title"])) 
        $title = var_dump($_atts["title"]);

回答1:


I used the following code:

if (isset($_atts["width"]))
    $width = var_dump($_atts["width"]);           
if (isset($_atts["title"])) 
    $title = var_dump($_atts["title"]);


来源:https://stackoverflow.com/questions/21318585/correcting-a-illegal-string-offset-warning-in-wordpress-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!