Page 1 of 1

PHP Compatibility - Array to string conversion

PostPosted: Thu Nov 08, 2012 5:18 pm
by seascoot
Hi Steve,

On testing the 2.0 alpha release on a new WAMP installation with PHP 5.4.3 I got a PHP notice:
PHP Notice: Array to string conversion in C:\wamp\www\xataface\lib\jscalendar\calendar.php on line 103


This is the relevant function.

Code: Select all
    function _make_js_hash($array) {
        $jstr = '';
        reset($array);
        while (list($key, $val) = each($array)) {
            if (is_bool($val))
      $val = $val ? 'true' : 'false';
            else if (!is_numeric($val))
                $val = '"'.$val.'"';
            if ($jstr) $jstr .= ',';
            $jstr .= '"' . $key . '":' . $val;
        }
        return $jstr;
    }


I was able to get rid of the notice by using implode. I also tried serialize, but could not get that to work.

Code: Select all
    function _make_js_hash($array) {
        $jstr = '';
        reset($array);
        while (list($key, $val) = each($array)) {
            if (is_bool($val))
               $val = $val ? 'true' : 'false';
         else if (is_array($val))
            $val = '"'.(implode($val)).'"';
            else if (!is_numeric($val))
                $val = '"'.$val.'"';
            if ($jstr) $jstr .= ',';
            $jstr .= '"' . $key . '":' . $val;
        }
        return $jstr;
    }


I think this is another case of later PHP versions being more picky. I'm posting this to bring it to your attention and hopefully confirm that it is an acceptable fix.

Re: PHP Compatibility - Array to string conversion

PostPosted: Fri Nov 09, 2012 8:59 am
by shannah
I suspect that the problem may be elsewhere, and more related to the data that is being sent to the calendar. Can you post the field definition (from the db and fields.ini) for the field that is causing this problem. It is likely a date field in your form.

Re: PHP Compatibility - Array to string conversion

PostPosted: Fri Nov 09, 2012 3:35 pm
by seascoot
Hi Steve,

The thing is, its a fairly straightforward data source. Its a date field in a new record form. There is no entry for the field in the fields.ini file, so I'm using the default calendar widget.

The database table field settings are:

# Name Type Collation Attributes Null Default Extra Action
1 Date datetime Yes NULL
2 OrganizationID int(11) Yes 0
3 ProductID int(11) Yes 0
4 Weight int(11) Yes 0
5 ID int(11) No None AUTO_INCREMENT