Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Aug 2004
    Posts
    762
    Plugin Contributions
    0

    Default PHP Fatal error: Call to a member function get_template_dir() on null in credit_cards

    I was editing our error logs, and I notice the occasional one that says this:

    Code:
    [30-Mar-2019 04:03:37 America/Los_Angeles] PHP Fatal error:  Call to a member function get_template_dir() on null in /home/server/public_html/store/includes/languages/english/credit_cards.php on line 46
    The line of code in that PHP file is this:

    Code:
    define('IMAGE_CC_ENABLED_VISA', zen_image($template->get_template_dir('cc1.gif', DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . 'cc1.gif'));
    Any idea how to remedy this? I do have the cc1.gif in my template_default/images
    - Jeff

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,491
    Plugin Contributions
    88

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    There's more to that error-log than just the "report", isn't there, that would show the 'backtrace' (i.e. who called who)?

  3. #3
    Join Date
    Aug 2004
    Posts
    762
    Plugin Contributions
    0

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    Quote Originally Posted by lat9 View Post
    There's more to that error-log than just the "report", isn't there, that would show the 'backtrace' (i.e. who called who)?
    No, that's literally the only thing in the MyDebug log file, and there aren't any accompanied error files before or after it in the log directory.

    Here is a screenshot to show you how they look, and the frequency: https://i.postimg.cc/7ZQNyfQq/screenshot-733.png
    - Jeff

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,491
    Plugin Contributions
    88

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    What changes are present in the store, e.g. plugins and/or your customizations? I'm just trying to visualize what's going on.

  5. #5
    Join Date
    Aug 2004
    Posts
    762
    Plugin Contributions
    0

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    Quote Originally Posted by lat9 View Post
    What changes are present in the store, e.g. plugins and/or your customizations? I'm just trying to visualize what's going on.
    Well, not sure where to start with that one! We're a large store that's been using (and modifying) ZenCart for 15 years. There's a lot of different plugins we have, but we are using the responsive_classic template.

    I wish there was more to the error message to perhaps point to why it's getting that specific error. Normally, like you said, there are other logs to indicate the source of the error....but I'm not seeing anything.

    All I have to work with is the error: Call to a member function get_template_dir() on null in credit_cards.php in line 46.
    - Jeff

  6. #6
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    What does your file: includes/extra_configures/enable_error_logging.php look like?

    The ZC 1.5.5 version of this file has this:
    Code:
    <?php
    /**
     * Very simple error logging to file
     *
     * Sometimes it is difficult to debug PHP background activities, especially when most information cannot be safely output to the screen.
     * However, using the PHP error logging facility we can store all PHP errors to a file, and then review separately.
     * Using this method, the debug details are stored at: /logs/myDEBUG-999999-00000000.log
     * Credits to @lat9 for adding backtrace functionality
     *
     * @package debug
     * @copyright Copyright 2003-2016 Zen Cart Development Team
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: Author: DrByte  Sat Oct 17 20:09:58 2015 -0400 Modified in v1.5.5 $
     */
    
    function zen_debug_error_handler ($errno, $errstr, $errfile, $errline) {
      if (!(error_reporting() & $errno)) {
        return;
      }
      ob_start();
      if (version_compare(PHP_VERSION, '5.3.6') >= 0) {
        debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
      } else {
        debug_print_backtrace();
      }
      $backtrace = ob_get_contents();
      ob_end_clean();
      // The following line removes the call to this zen_debug_error_handler function (as it's not relevant)
      $backtrace = preg_replace ('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '', $backtrace, 1);  
      error_log('Request URI: ' . $_SERVER['REQUEST_URI'] . ', IP address: ' . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'not set') . "\n" . $backtrace);
      
      return false;  // Let PHP's built-in error handler do its thing.
    }
    Which should provide the backtrace information that lat9 was asking about and provide much more than just the result of the program stopping.

    It also seems to indicate that the language file(s) are loaded before the template has been identified which is what the error message is indicating: $template is undefined and therefore trying to access the method get_template_dir causes the error described. The question becomes why/how is that possible when $template is to be defined at load point 100 and the language to be identified after that at load point 110 with language files loaded then or later...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  7. #7
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,695
    Plugin Contributions
    123

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    Can you modify
    includes/languages/english/credit_cards.php

    and add

    global $template;

    at the top (after the PHP open) to see if that fixes it?
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  8. #8
    Join Date
    Aug 2004
    Posts
    762
    Plugin Contributions
    0

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    Quote Originally Posted by mc12345678 View Post
    What does your file: includes/extra_configures/enable_error_logging.php look like?
    This is what mine looks like (appears to be the same as yours):

    Code:
    function zen_debug_error_handler ($errno, $errstr, $errfile, $errline) {
      if (!(error_reporting() & $errno)) {
        return;
      }
      ob_start();
      if (version_compare(PHP_VERSION, '5.3.6') >= 0) {
        debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
      } else {
        debug_print_backtrace();
      }
      $backtrace = ob_get_contents();
      ob_end_clean();
      // The following line removes the call to this zen_debug_error_handler function (as it's not relevant)
      $backtrace = preg_replace ('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '', $backtrace, 1);  
      error_log('Request URI: ' . $_SERVER['REQUEST_URI'] . ', IP address: ' . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'not set') . "\n" . $backtrace);
      
      return false;  // Let PHP's built-in error handler do its thing.
    }
    - Jeff

  9. #9
    Join Date
    Aug 2004
    Posts
    762
    Plugin Contributions
    0

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    Quote Originally Posted by swguy View Post
    Can you modify
    includes/languages/english/credit_cards.php

    and add

    global $template;

    at the top (after the PHP open) to see if that fixes it?
    Okay, I just added it to the top of that file (just after the <?php start). I erased all log files and will monitor to see what happens. Will keep you posted!
    - Jeff

  10. #10
    Join Date
    Aug 2004
    Posts
    762
    Plugin Contributions
    0

    Default Re: PHP Fatal error: Call to a member function get_template_dir() on null in credit_c

    UPDATE: It's still happening, even though I added the Global $template variable on top of the file.

    Here is a screenshot to show the frequency in the log file:

    https://i.postimg.cc/LsJ9H87K/screenshot-736.png

    Keep in mind:

    * This does NOT seem to correspond with every customer order. In other words, according to the log files, this error only happened twice......but we have gotten about 20 orders in that time span.

    * I am trying to see if the errors correspond to any particular order (to isolate something about them), but so far, I can't find any orders that match the exact time shown on the error file.

    So I am not sure how much this is impacting business (since the error is infrequent and orders still are being placed). However, any error is worth trying to troubleshoot, and I'm at a complete loss what is causing it.

    Once in a blue moon, I get customers who complain that when inputting Credit Card information on Step 2 of the checkout process, the screen goes white. I wonder if those complaints are related to this? That "white screen" issue is something I've never been able to reproduce or resolve, and I usually have to manually bill the customer off the website whenever they experience a problem like that.

    Any more ideas or troubleshooting tips is appreciated.
    - Jeff

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v155 PHP Fatal error: Call to a member function isMobile() on null
    By asdco in forum Basic Configuration
    Replies: 5
    Last Post: 12 Oct 2018, 11:03 AM
  2. Replies: 6
    Last Post: 21 Jun 2012, 12:16 AM
  3. Replies: 2
    Last Post: 16 Nov 2011, 05:29 AM
  4. Fatal error: Call to a member function get_template_dir() -- wordpress mod
    By rakhi in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 3 Jul 2007, 09:30 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