PHP Compatibility - Array to string conversion

A place for users and developers of the Xataface to discuss and receive support.

PHP Compatibility - Array to string conversion

Postby seascoot » Thu Nov 08, 2012 5:18 pm

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.
seascoot
 
Posts: 3
Joined: Sun Oct 21, 2012 11:52 am

Re: PHP Compatibility - Array to string conversion

Postby shannah » Fri Nov 09, 2012 8:59 am

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.
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: PHP Compatibility - Array to string conversion

Postby seascoot » Fri Nov 09, 2012 3:35 pm

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
seascoot
 
Posts: 3
Joined: Sun Oct 21, 2012 11:52 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 28 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved