Page 1 of 4 123 ... LastLast
Results 1 to 10 of 37
  1. #1
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    3,508
    Plugin Contributions
    33

    Default PHP 5.4 warnings: Illegal string offset

    Using a stock v1.5.1 install (localhost) running php 5.4.8 on Windows 7. Added the product New v1.2 -> Downloads -> Single Download to my cart, signed in and clicked the Checkout button. I was properly redirected to the checkout_payment page, but had two debug*.log files generated:

    Code:
    [19-Nov-2012 20:12:07 Europe/Berlin] PHP Warning:  Illegal string offset 'cost' in C:\xampp\htdocs\v1.5.1\includes\classes\order.php on line 355
    
    [19-Nov-2012 20:12:07 Europe/Berlin] PHP Warning:  Illegal string offset 'title' in C:\xampp\htdocs\v1.5.1\includes\modules\pages\checkout_shipping\header_php.php on line 88
    Code:
    [19-Nov-2012 20:12:08 Europe/Berlin] PHP Warning:  Illegal string offset 'cost' in C:\xampp\htdocs\v1.5.1\includes\classes\order.php on line 355
    
    [19-Nov-2012 20:12:08 Europe/Berlin] PHP Warning:  Illegal string offset 'id' in C:\xampp\htdocs\v1.5.1\includes\classes\shipping.php on line 32
    
    [19-Nov-2012 20:12:08 Europe/Berlin] PHP Warning:  Illegal string offset 'id' in C:\xampp\htdocs\v1.5.1\includes\classes\shipping.php on line 32
    
    [19-Nov-2012 20:12:08 Europe/Berlin] PHP Warning:  Illegal string offset 'id' in C:\xampp\htdocs\v1.5.1\includes\modules\order_total\ot_shipping.php on line 41
    
    [19-Nov-2012 20:12:08 Europe/Berlin] PHP Warning:  Illegal string offset 'id' in C:\xampp\htdocs\v1.5.1\includes\modules\order_total\ot_shipping.php on line 41
    In each case, the illegal offset is associated with an undefined array element. For example, line 355 of order.php contains:
    Code:
                            'shipping_cost' => $_SESSION['shipping']['cost'],
    I'm not quite sure how to proceed. Are these warnings indicative of something that might become errors in a future version of PHP?

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    3,508
    Plugin Contributions
    33

    Default Re: PHP 5.4 warnings: Illegal string offset

    OK, according to http://php.net/manual/en/language.types.string.php:

    "As of PHP 5.4 string offsets have to either be integers or integer-like strings, otherwise a warning will be thrown. Previously an offset like "foo" was silently cast to 0."

    It looks like a relatively small change to three files removes the warning:

    /includes/modules/pages/checkout_shipping/header_php.php, starting around line 70:
    Code:
    /*-bof BUGFIX: lat9-d
      require(DIR_WS_CLASSES . 'order.php');
      $order = new order;
      -eof BUGFIX: lat9-d */
    // register a random ID in the session to check throughout the checkout procedure
    // against alterations in the shopping cart contents
    if (isset($_SESSION['cart']->cartID)) {
      if (!isset($_SESSION['cartID']) || $_SESSION['cart']->cartID != $_SESSION['cartID']) {
        $_SESSION['cartID'] = $_SESSION['cart']->cartID;
      }
    } else {
      zen_redirect(zen_href_link(FILENAME_TIME_OUT));
    }
    
    // if the order contains only virtual products, forward the customer to the billing page as
    // a shipping address is not needed
    //  if ($order->content_type == 'virtual') { BUGFIX: lat9-d
      if ($_SESSION['cart']->get_content_type() == 'virtual') {  /* BUGFIX: lat9-a */
    //    $_SESSION['shipping'] = 'free_free';  BUGFIX: lat9-d
        $_SESSION['shipping']['title'] = 'free_free';
        $_SESSION['shipping']['id'] = 'free_free';  /* BUGFIX: lat9-a */
        $_SESSION['shipping']['cost'] = 0;  /*BUGFIX: lat9-a */
        $_SESSION['sendto'] = false;
        zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
      }
      
      require(DIR_WS_CLASSES . 'order.php');  /* BUGFIX: lat9-a */
      $order = new order;  /* BUGFIX: lat9-a */
    /includes/modules/pages/checkout_payment/header_php.php (line 36):
    Code:
    if (isset($_SESSION['shipping']['id']) && $_SESSION['shipping']['id'] == 'free_free' && defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER') /*-bof BUGFIX lat9-a */ && $_SESSION['cart']->get_content_type() != 'virtual' /*-eof BUGFIX lat9-a */ && $_SESSION['cart']->show_total() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
      zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
    }
    /includes/modules/pages/checkout_confirmation/header_php.php (line 43):
    Code:
    if (isset($_SESSION['shipping']['id']) && $_SESSION['shipping']['id'] == 'free_free' && defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER') /*-bof BUGFIX lat9-a */ && $_SESSION['cart']->get_content_type() != 'virtual' /*-eof BUGFIX lat9-a */ && $_SESSION['cart']->show_total() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    3,508
    Plugin Contributions
    33

    Default Re: PHP 5.4 warnings: Illegal string offset

    OK, make that four files ...

    /includes/modules/order_total/ot_shipping.php (line 77 in v1.5.1); change from
    Code:
            if ($_SESSION['shipping'] == 'free_free') {
              $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
              $order->info['shipping_cost'] = 0;
            }
    to
    Code:
            if ($_SESSION['shipping']['id'] == 'free_free') {
              $order->info['shipping_method'] = FREE_SHIPPING_TITLE;
              $order->info['shipping_cost'] = 0;
            }

  4. #4
    Join Date
    Aug 2011
    Location
    Tampa Bay, Florida USA
    Posts
    11
    Plugin Contributions
    0

    Default Re: PHP 5.4 warnings: Illegal string offset

    [04-Feb-2013 06:37:25 Australia/Melbourne] PHP Warning: Illegal string offset 'cost' in /../../../htdocs/store/includes/classes/order.php on line 349

    not sure how to remedy this? thanks, Lora

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    3,508
    Plugin Contributions
    33

    Default Re: PHP 5.4 warnings: Illegal string offset

    Quote Originally Posted by rozdesignz View Post
    [04-Feb-2013 06:37:25 Australia/Melbourne] PHP Warning: Illegal string offset 'cost' in /../../../htdocs/store/includes/classes/order.php on line 349

    not sure how to remedy this? thanks, Lora
    Lora, what shipping module are you using?

  6. #6
    Join Date
    Dec 2009
    Location
    The Netherlands
    Posts
    1,305
    Plugin Contributions
    9

    Default Re: PHP 5.4 warnings: Illegal string offset

    I am getting this error:

    Code:
    [17-Mar-2013 16:29:43 UTC] PHP Warning:  Illegal string offset 'id' in /var/www/vhost/design75/public_html/includes/modules/payment/moneyorder.php on line 40
    This is line 40
    PHP Code:
            $check $db->Execute("select zone_id from " TABLE_ZONES_TO_GEO_ZONES " where geo_zone_id = '" MODULE_PAYMENT_MONEYORDER_ZONE "' and zone_country_id = '" $order->billing['country']['id'] . "' order by zone_id"); 
    using Zen Cart 1.5.1 with PHP version: 5.4.6-1

    I am going to implement the above fixes to see if the error is still generated. I will report back with my findings

  7. #7
    Join Date
    Dec 2009
    Location
    The Netherlands
    Posts
    1,305
    Plugin Contributions
    9

    Default Re: PHP 5.4 warnings: Illegal string offset

    no joy, the error is still there

  8. #8
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    3,508
    Plugin Contributions
    33

    Default Re: PHP 5.4 warnings: Illegal string offset

    Design75, I'm not getting that error for the moneyorder payment class. I've got an unmodified v1.5.1 version of /includes/classes/order.php, which sets the billing['country']['id'] value into the order in the cart() function on line 428.

  9. #9
    Join Date
    Jan 2004
    Posts
    60,425
    Blog Entries
    4
    Plugin Contributions
    144

    Default Re: PHP 5.4 warnings: Illegal string offset

    Quote Originally Posted by lat9 View Post
    /includes/modules/pages/checkout_payment/header_php.php (line 36):
    Code:
    if (isset($_SESSION['shipping']['id']) && $_SESSION['shipping']['id'] == 'free_free' && defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER') /*-bof BUGFIX lat9-a */ && $_SESSION['cart']->get_content_type() != 'virtual' /*-eof BUGFIX lat9-a */ && $_SESSION['cart']->show_total() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
      zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
    }
    /includes/modules/pages/checkout_confirmation/header_php.php (line 43):
    Code:
    if (isset($_SESSION['shipping']['id']) && $_SESSION['shipping']['id'] == 'free_free' && defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER') /*-bof BUGFIX lat9-a */ && $_SESSION['cart']->get_content_type() != 'virtual' /*-eof BUGFIX lat9-a */ && $_SESSION['cart']->show_total() < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
    Wouldn't making those changes specifically cause problems with virtual products?
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donations always welcome: www.zen-cart.com/donate

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.



  10. #10
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    3,508
    Plugin Contributions
    33

    Default Re: PHP 5.4 warnings: Illegal string offset

    Quote Originally Posted by DrByte View Post
    Wouldn't making those changes specifically cause problems with virtual products?
    I don't think so, since the redirect won't ever happen if the cart contains only virtual products. Quite honestly, it's been so long since I tackled this that I don't remember why the virtual-product exclusion was necessary ... but I apparently thought so at the time.

 

 
Page 1 of 4 123 ... LastLast

Similar Threads

  1. Replies: 1
    Last Post: 18 Jan 2012, 11:50 AM
  2. Can't access admin page-Offset not contained in string
    By bpoilspill in forum General Questions
    Replies: 8
    Last Post: 20 Jul 2011, 10:35 PM
  3. UPSXML error: Cannot use string offset as an array
    By callingrohit in forum Addon Shipping Modules
    Replies: 9
    Last Post: 16 Sep 2008, 06:23 PM
  4. Fatal error: Cannot use string offset as an array in upsxml.php
    By yaby in forum Addon Shipping Modules
    Replies: 4
    Last Post: 19 Oct 2007, 06:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •