Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Oct 2012
    Posts
    60
    Plugin Contributions
    0

    Default This piece of code works with php5.6 but crashes site with all versions of php7

    I am using theme files I bought from Template Monster in 2013. It was half-assed from the beginning, but I eventually got it working great, customized it further, and still love it.

    I can't upgrade to php7 without this piece of code in the tpl-header.php crashing everything. It is code to select the currency. This works fine with php5.6, but causes the website to work not with any version of php7.

    Perhaps someone can point me in the right direction.

    <!-- ========== CURRENCIES ========= -->

    <?php echo zen_draw_form('currencies', zen_href_link(basename(ereg_replace('.php','', $PHP_SELF)), '', $request_type, false), 'get'); ?>
    <div>
    <span class="label"><?php echo BOX_HEADING_CURRENCIES;?>: &nbsp;</span>

    <?php
    if (isset($currencies) && is_object($currencies)) {

    reset($currencies->currencies);
    $currencies_array = array();
    while (list($key, $value) = each($currencies->currencies)) {
    $currencies_array[] = array('id' => $key, 'text' => $value['title']);
    }

    $hidden_get_variables = '';
    reset($_GET);
    while (list($key, $value) = each($_GET)) {
    if ( ($key != 'currency') && ($key != zen_session_name()) && ($key != 'x') && ($key != 'y') ) {
    $hidden_get_variables .= zen_draw_hidden_field($key, $value);
    }
    }
    }
    ?>
    <?php echo zen_draw_pull_down_menu('currency', $currencies_array, $_SESSION['currency'], 'class="select" onchange="this.form.submit();"') . $hidden_get_variables . zen_hide_session_id()?>
    </div>

    </form>
    <!-- ====================================== -->

  2. #2
    Join Date
    Jul 2012
    Posts
    14,854
    Plugin Contributions
    17

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    Two major issues: use of `ereg_replace()` and `list() = each()`

    The first is addressed by use of the proper preg_replace() format.
    The second by changing out:
    Code:
    while (list($key, $value) = each($currencies->currencies)) {
    With:
    Code:
    foreach ($currencies->currencies as $key => $value) {
    And the similar with $_GET:
    Code:
    foreach ($_GET as $key => $value) {
    But don't have to have the reset($_GET) because foreach always starts at the beginning as if reset is called already.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  3. #3
    Join Date
    Oct 2012
    Posts
    60
    Plugin Contributions
    0

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    Thanks for your help! I got it working. Seems PHP did away with the ereg_replace command entirely. I hate software that is not backward compatible like that.


    I still found another problem, I'll have to isolate the code. However, I had my site running on php7.2 overnight and it worked well enough that two people place orders. This is a huge relief. I've been wondering what to do for the past year. I put it back in 5.6 for now until I have a chance to try to isolate the next (and hopefully last) piece of code that is messing up.





    Quote Originally Posted by mc12345678 View Post
    Two major issues: use of `ereg_replace()` and `list() = each()`

    The first is addressed by use of the proper preg_replace() format.
    The second by changing out:
    Code:
    while (list($key, $value) = each($currencies->currencies)) {
    With:
    Code:
    foreach ($currencies->currencies as $key => $value) {
    And the similar with $_GET:
    Code:
    foreach ($_GET as $key => $value) {
    But don't have to have the reset($_GET) because foreach always starts at the beginning as if reset is called already.

  4. #4
    Join Date
    Oct 2012
    Posts
    60
    Plugin Contributions
    0

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    The problem I have now seems to be that category_row.php crashes, I am trying to get it to work using just the default category_row.php, but it still crashes when I switch to php7.2

    When I switch from 5.6 to 7.2, the last thing that comes up in the code is my comment "category row begin," but it doesn't show "category row end." I also put a comment at the beginning of tpl_list_box_content.php and it does not come up when I switch to php7.2 either.






    <!-- default category row begin -->


    <?php
    /**
    * index category_row.php
    *
    * Prepares the content for displaying a category's sub-category listing in grid format.
    * Once the data is prepared, it calls the standard tpl_list_box_content template for display.
    *
    * @package page
    * @copyright Copyright 2003-2006 Zen Cart Development Team
    * @copyright Portions Copyright 2003 osCommerce
    * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
    * @version $Id: category_row.php 4084 2006-08-06 23:59:36Z drbyte $
    */


    if (!defined('IS_ADMIN_FLAG')) {
    die('Illegal Access');
    }
    $title = '';
    $num_categories = $categories->RecordCount();

    $row = 0;
    $col = 0;
    $list_box_contents = '';
    if ($num_categories > 0) {
    if ($num_categories < MAX_DISPLAY_CATEGORIES_PER_ROW || MAX_DISPLAY_CATEGORIES_PER_ROW == 0) {
    $col_width = floor(100/$num_categories);
    } else {
    $col_width = floor(100/MAX_DISPLAY_CATEGORIES_PER_ROW);
    }

    while (!$categories->EOF) {
    if (!$categories->fields['categories_image']) !$categories->fields['categories_image'] = 'pixel_trans.gif';
    $cPath_new = zen_get_path($categories->fields['categories_id']);

    // strip out 0_ from top level cats
    $cPath_new = str_replace('=0_', '=', $cPath_new);

    // $categories->fields['products_name'] = zen_get_products_name($categories->fields['products_id']);

    $list_box_contents[$row][$col] = array('params' => 'class="categoryListBoxContents"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' => '<a href="' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . zen_image(DIR_WS_IMAGES . $categories->fields['categories_image'], $categories->fields['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories->fields['categories_name'] . '</a>');

    $col ++;
    if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
    $col = 0;
    $row ++;
    }
    $categories->MoveNext();
    }
    }
    ?>


    <!-- default category row complete -->

  5. #5
    Join Date
    Oct 2012
    Posts
    60
    Plugin Contributions
    0

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    It is generating an error

    [17-Jan-2020 13:31:41 America/New_York] Request URI: /index.php?main_page=index&cPath=117, IP address:
    #1 navigationHistory->add_current_page() called at [/home/patriot/public_html/includes/autoload_func.php:87]
    #2 require(/home/patriot/public_html/includes/autoload_func.php) called at [/home/patriot/public_html/includes/application_top.php:170]
    #3 require(/home/patriot/public_html/includes/application_top.php) called at [/home/patriot/public_html/index.php:26]

    [17-Jan-2020 13:31:41 America/New_York] PHP Warning: Illegal string offset 'cPath' in /home/patriot/public_html/includes/classes/navigation_history.php on line 43
    [17-Jan-2020 13:31:41 America/New_York] PHP Fatal error: Uncaught Error: Cannot use string offset as an array in /home/patriot/public_html/includes/modules/theme610/category_row.php:45
    Stack trace:
    #0 /home/patriot/public_html/includes/templates/template_default/templates/tpl_modules_category_row.php(14): require()
    #1 /home/patriot/public_html/includes/templates/theme610/templates/tpl_index_categories.php(88): require('/home/patriot/p...')
    #2 /home/patriot/public_html/includes/modules/pages/index/main_template_vars.php(236): require('/home/patriot/p...')
    #3 /home/patriot/public_html/includes/templates/theme610/common/tpl_main_page.php(231): require('/home/patriot/p...')
    #4 /home/patriot/public_html/index.php(97): require('/home/patriot/p...')
    #5 {main}
    thrown in /home/patriot/public_html/includes/modules/theme610/category_row.php on line 45

  6. #6
    Join Date
    Jul 2012
    Posts
    14,854
    Plugin Contributions
    17

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    To be a little bit of a smart alec, actually the issue is not that the code is not backwards compatible (because it is), but instead it wasn't forwards compatible.

    As to how to figure some of the things out... well there's a number of tools and resources available. I came into the php code what I would call "late" in the game (5.2.7 was the first version I came to know.)

    Anyways, I really think what would help you most is to take a look at the myDebug log files generated in the logs folder. That should identify the line at which a problem is occurring and give a general idea of what the real problem is. It may then take a little bit to figure out where the problem really started, but pay attention to the first entry of the most recent file. Other issues below that tend to stem from those further up in the file (with some exceptions)...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  7. #7
    Join Date
    Oct 2012
    Posts
    60
    Plugin Contributions
    0

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    Quote Originally Posted by mc12345678 View Post
    To be a little bit of a smart alec, actually the issue is not that the code is not backwards compatible (because it is), but instead it wasn't forwards compatible.

    As to how to figure some of the things out... well there's a number of tools and resources available. I came into the php code what I would call "late" in the game (5.2.7 was the first version I came to know.)

    Anyways, I really think what would help you most is to take a look at the myDebug log files generated in the logs folder. That should identify the line at which a problem is occurring and give a general idea of what the real problem is. It may then take a little bit to figure out where the problem really started, but pay attention to the first entry of the most recent file. Other issues below that tend to stem from those further up in the file (with some exceptions)...
    I discovered it was also crashing on items with additional pictures and generating a similar error

    [17-Jan-2020 16:52:37 America/New_York] PHP Warning: Illegal string offset 'products_id' in /home/patriot/public_html/includes/classes/navigation_history.php on line 43
    [17-Jan-2020 16:52:37 America/New_York] PHP Fatal error: Uncaught Error: Cannot use string offset as an array in /home/patriot/public_html/includes/modules/theme610/additional_images.php:104
    Stack trace:
    #0 /home/patriot/public_html/includes/templates/theme610/templates/tpl_product_info_display.php(87): require()
    #1 /home/patriot/public_html/includes/modules/pages/product_info/main_template_vars.php(178): require('/home/patriot/p...')
    #2 /home/patriot/public_html/includes/templates/theme610/common/tpl_main_page.php(231): require('/home/patriot/p...')
    #3 /home/patriot/public_html/index.php(97): require('/home/patriot/p...')
    #4 {main}
    thrown in /home/patriot/public_html/includes/modules/theme610/additional_images.php on line 104

    This time I found a tip on the forum to switch $list_box_contents = ""; with $list_box_contents = array(); in the additional_images.php file. It worked!

    I'm still fighting with it to get the grid of category images to come up with higher version php 7.

  8. #8
    Join Date
    Oct 2012
    Posts
    60
    Plugin Contributions
    0

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    I just did the same fix on category_row.php

    I changed $list_box_contents = ''; to $list_box_contents = array();

    I appears to have fixed it! The category picture grid is shoing up on php 7 now!


    The thing that was driving me crazy all day is the stock category_row.php file in Zencart 1.5.5a uses $list_box_contents = ''; I just unzipped a copy of the lastest Zen-Cart and in the newest one it uses an array.

  9. #9
    Join Date
    Jul 2012
    Posts
    14,854
    Plugin Contributions
    17

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    Quote Originally Posted by patrioticflags View Post
    I just did the same fix on category_row.php

    I changed $list_box_contents = ''; to $list_box_contents = array();

    I appears to have fixed it! The category picture grid is shoing up on php 7 now!


    The thing that was driving me crazy all day is the stock category_row.php file in Zencart 1.5.5a uses $list_box_contents = ''; I just unzipped a copy of the lastest Zen-Cart and in the newest one it uses an array.
    Yes more recent versions have been modified to suit the increased strictness of more recent php versions. It used to be possible to just assign something to say an empty set of quotes and then do pretty much anything desired with it because it was "empty". Now though there is a greater expectation (as with most other programming languages) to identify how the variable is going to be used and then that way when an action is incorporated the base php software can just do what is needed. Understand that basically instead of the php software being bloated to correct programmers "mistakes" (random assignment of variable), now and continuing forwards the software just reports that the code doesn't work (with helpful information) and needs to be corrected.

    Some of the other reasons for this besides removing bloat and increasing speed is that the object (variable) can be worked with as originally intended rather than allowing some sort of Web side insertion of information that may be handled differently than originally intended. That other information may cause undesired action or worse access to manipulate the site. So. Better identification of variables to limit their ability to affect site operation also increases site security which is obviously still an expectation and desire for eCommerce.

    Long and short, keep your site software up-to-date so that the best features and security can be maintained...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...
    Upgraded to Zen Cart V1.5.3 from V1.5.1 from V1.5.0 from V1.3.9h

  10. #10
    Join Date
    Jan 2019
    Location
    UK
    Posts
    19
    Plugin Contributions
    0

    Default Re: This piece of code works with php5.6 but crashes site with all versions of php7

    I've been having the same problems with php incompatiblilty due to my template being quite old, and have very limited knowledge on code so have been struggling to change the listbox to an array in a way that does not break my website. I wonder if you would be so kind as to post the chunk of code you changed in category_row.php to make it compatible with php7?

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Help with code piece
    By yaseent in forum Code Collaboration
    Replies: 16
    Last Post: 18 Feb 2018, 03:44 AM
  2. I am happy to stick with 1.3.8a, it works but must I upgrade?
    By amdowney in forum Upgrading from 1.3.x to 1.3.9
    Replies: 4
    Last Post: 2 Jun 2011, 01:21 PM
  3. Replies: 10
    Last Post: 4 Mar 2011, 01:05 AM
  4. download works with english but not swedish
    By Rabarbervin in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 12 Jan 2011, 02:39 AM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR