Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

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

Open
5 of 6 tasks
ouun opened this issue Aug 23, 2018 · 10 comments
Open
5 of 6 tasks

Comments

@ouun
Copy link

ouun commented Aug 23, 2018

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

@mmirus
Copy link
Contributor

mmirus commented Aug 23, 2018

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.

@mejta
Copy link
Contributor

mejta commented Aug 24, 2018

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.

@ouun
Copy link
Author

ouun commented Aug 28, 2018

@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.

@mejta
Copy link
Contributor

mejta commented Sep 25, 2018

@ouun Any news on this issue?

@mejta
Copy link
Contributor

mejta commented Sep 29, 2018

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

@mmirus mmirus closed this as completed Oct 2, 2018
@ouun
Copy link
Author

ouun commented Mar 7, 2019

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

@mmirus
Copy link
Contributor

mmirus commented May 10, 2019

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 mmirus reopened this May 10, 2019
@ouun
Copy link
Author

ouun commented May 11, 2019

@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.

@bdkabiruddin
Copy link

I am facing same issue, Any solution?

@ouun
Copy link
Author

ouun commented Nov 11, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants