sage-woocommerce icon indicating copy to clipboard operation
sage-woocommerce copied to clipboard

Fatal error: Uncaught Error: Maximum function nesting level of '200' reached, aborting!

Open ouun opened this issue 7 years ago • 10 comments
trafficstars

Submit a feature request or bug report


What is the current behavior?

Installing version 1.0.2 with the new action 'woocommerce_before_template_part' leads to the php error Fatal error: Uncaught Error: Maximum function nesting level of '200' reached, aborting!

What might be the solution?

I'm wondering if the additional add_action is needed. In my current setup I included the passing of $data diretly into add_filter('template_include', ...):

       add_filter('template_include', function ($template) {

            $overwrites = ['single-product', 'archive-product', 'taxonomy-product_cat', 'taxonomy-product_tag'];

            if ( ($key = array_search( basename($template, ".php"), $overwrites)) !== FALSE ) {
                $blade_file = locate_template( WC()->template_path() . $overwrites[$key] );
            }

            $template = !empty($blade_file) ? $blade_file : $template;

            $data = collect( get_body_class() )->reduce( function ( $data, $class ) use ( $template ) { //use body class to get correct controller data
                return apply_filters( "sage/template/{$class}/data", $data, $template ); //get data from controller
            }, [] );

            if ( $template ) {
                echo template( $template, $data );
                return get_stylesheet_directory() . '/index.php';
            }

            return locate_template( 'woocommerce' );

        }, 100);

I'm currently not sure whether this has the same result, but maybe it's useful.

Best

ouun avatar Aug 23 '18 22:08 ouun

Thanks for reporting, @ouun. Can you provide any more details on when this occurs to help us track down the issue? I spun up a very, very simple test site with the WooCommerce sample data and overrode single-product.php and didn't hit the error. @mejta may have better insight into this, as well.

mmirus avatar Aug 23 '18 23:08 mmirus

Hi @ouun, I've tried to replicate the issue, but with no success. I have a setup with more than 20 templates overwritten and I cannot run into the issue. It would be helpful if you provide full error/exception and piece of code that demonstrates the issue. Thank you.

mejta avatar Aug 24 '18 06:08 mejta

@mmirus & @mejta thanks for your replies. I’ll follow up next week with some more details as I currently don’t have access to my computer.

ouun avatar Aug 28 '18 08:08 ouun

@ouun Any news on this issue?

mejta avatar Sep 25 '18 13:09 mejta

@mmirus I suggest closing this issue. No reply from author and I cannot reproduce it.

mejta avatar Sep 29 '18 19:09 mejta

Dear @mejta & @mmirus , I have to apologize for never answering. I had to pause the project and just started to follow up and came to this again as I still face the same issue: Fatal error: Uncaught Error: Maximum function nesting level of '200' reached, aborting! in/current/web/wp/wp-includes/functions.php:6090. I'm using the full roots stack here with Trellis, Bedrock & Sage and I'm on local dev env.

The error is thrown by "xdebug" and I already changed the xdebug_max_nesting_levelup to 500. However now I get a "502" or Fatal error: Allowed memory size of 100663296 bytes exhaustederror.

So far I do not understand why the data collection within 'woocommerce_before_template_part' results in the mentioned errors, but using an empty array instead of the following solves it:

$data = collect( get_body_class() )->reduce( function ( $data, $class ) use ( $theme_template ) { //use body class to get correct controller data apply_filters( "sage/template/{$class}/data", $data, $theme_template ); }, [] );

I also tried to set all available classes directly into the filter one by one. E.g. on a single product page I have the following body classes: product-template-default single single-product postid-33 logged-in admin-bar no-customize-support custom-background woocommerce woocommerce-page woocommerce-no-js v-neck-t-shirt app-data index-data singular-data single-data single-product-data single-product-v-neck-t-shirt-data debug-bar-maximized

I just hardcoded them one by one to the data filter such as for app-data apply_filters("sage/template/app-data/data", $data) to find out that I had two Conrollers making trouble:

1.) For the class 'index-data' while the Controller template for SingleIndex.php is the untouched example from sage repo.

2.) For 'single-product-data' as the Controller file included a function which was finally repeating itself when called for template parts.

I fixed both but still wonder whether it is not possible to just pass the same $data to all template parts without collecting them again and again.

Best regards,

Philipp

Currently I try to understand the usecase and benefit Not sure that I can follow the logic here but the $data object should be already available from loading the main template. I guess that this is used to make the $data also availabe

ouun avatar Mar 07 '19 16:03 ouun

Hey @ouun - sorry for the slow response here. I don't have the bandwidth to troubleshoot right now, especially with Sage 10 on the way, but I'm going to reopen this issue so that it's visible down the road. Thanks for sharing the additional info.

mmirus avatar May 10 '19 18:05 mmirus

@mmirus thanks for your kind folow up. I'm following the github repo and with that the Sage 10 development with very high interest. Go for it, please! Another note to add to my previous comment: Using Trellis I faced the Error: Maximum function nesting level of '{ A NUMBER}' reached, aborting! later again and solved it using higher nginx_fastcgi_buffers and nginx_fastcgi_buffer_size in the NGINX config. So far it helps and even reduced the single page load time in the local env from >10s to <5s. As I'm on a Multisite (& Multi-Network) environment not only running with WooCommerce I assume that the default value is simply to low in the Trellis NGINX settings.

ouun avatar May 11 '19 12:05 ouun

I am facing same issue, Any solution?

bdkabiruddin avatar Nov 10 '20 20:11 bdkabiruddin

I am facing same issue, Any solution?

I switched to Sage 10 and built my own integration: https://github.com/ouun/stage-woocommerce For Sage 9 it is too long ago and I can't remember how I continued. Sorry.

ouun avatar Nov 11 '20 10:11 ouun