Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Error: Uncaught Error: Class 'Timber\Timber' not found after update from 0.22.6 to 1.5.2 #1581

Closed
gsalkin opened this issue Oct 13, 2017 · 10 comments
Labels

Comments

@gsalkin
Copy link

gsalkin commented Oct 13, 2017

Expected behavior

I recently began the upgrade procedure for updating from 0.22.6 to the current release 1.5.2. I've made the necessary changes to continue to support Routes; removed deprecated methods etc. My site loads fine on a local machine (VM running CentOS 7.2 w/ nginx and PHP 7)

Actual behavior

On my staging server, the site will not load and instead posts the following errors:

Warning: include(/var/www/my-site/public/content/plugins/timber-library/lib/Timber.php): failed to open stream: No such file or directory in /var/www/my-site/public/content/vendor/composer/ClassLoader.php on line 412

Warning: include(): Failed opening '/var/www/my-site/public/content/plugins/timber-library/lib/Timber.php' for inclusion (include_path='.:/usr/share/pear7:/usr/share/php7') in /var/www/my-site/public/content/vendor/composer/ClassLoader.php on line 412

Fatal error: Uncaught Error: Class 'Timber\Timber' not found in /var/www/my-site/public/content/plugins/timber-library/timber.php:21 Stack trace: #0 /var/www/my-site/public/wp/wp-settings.php(303): include_once() #1 /var/www/my-site/public/wp/wp-config.php(10): require_once('/var/www/aspen/...') #2 /var/www/my-site/public/wp/wp-load.php(37): require_once('/var/www/aspen/...') #3 /var/www/my-site/public/wp/wp-blog-header.php(13): require_once('/var/www/aspen/...') #4 /var/www/my-site/public/index.php(7): require('/var/www/my-site/...') #5 {main} thrown in /var/www/my-site/public/content/plugins/timber-library/timber.php on line 21

Steps to reproduce behavior

Happens on site load.

What version of WordPress, PHP and Timber are you using?

WordPress 4.8.2 with PHP 7.0.23 and Timber 1.5.2

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)

I tried updating Timber two ways. First used Composer and Packagist but saw this old issue #1308 where there can be issues from updating Timber via Composer. Did a revert of my composer.json and tried installing via the plugin updater. Still having the same issues.

@gsalkin gsalkin changed the title Uncaught Error: Class 'Timber\Timber' not found after update from 0.22.6 to 1.5.2 Fatal Error: Uncaught Error: Class 'Timber\Timber' not found after update from 0.22.6 to 1.5.2 Oct 13, 2017
@drskullster
Copy link

I think this has to do with Timber being namespaced now (see releases/tag/1.0.0-rc3).

You can solve the issue by using Timber\Timber instead of Timber in your PHP files. But you should be aware that there are also breaking changes in the class names. For example, TimberPost became Timber\Post.

See new doc "Reference" section for a list of all available classes : https://timber.github.io/docs/reference/

@gsalkin
Copy link
Author

gsalkin commented Oct 16, 2017

Is that true for things like TimberSite as well? Seems that the documentation isn't super clear on that.

I'll give that a try though and report back. Thanks!

@drskullster
Copy link

yup, it seems that documentation, as well as the starter theme, still refers to 0.* versions.

You can move from

class MySite extends TimberSite {

to

class MySite extends Timber\Site {

@gsalkin
Copy link
Author

gsalkin commented Oct 16, 2017

Wow, ok thanks. @jarednova what would be the best way to submit a change for that documentation page?

As a followup on namespacing (forgive me, it's a newer concept to me) does that also apply to the TimberPost function that can be used on .twig files? For example, should:

{% for item in TimberPost(featured) %}
        {%- include "foo.twig" with {
            "foo": bar,
            "bar": foo
        }
     -%}

Be changed to:

{% for item in Timber\Post(featured) %}
        {%- include "foo.twig" with {
            "foo": bar,
            "bar": foo
        }
     -%}

@drskullster
Copy link

Twig function names didn't change.

See here : https://github.com/timber/timber/blob/master/lib/Twig.php#L52

@gchtr gchtr added the docs label Oct 16, 2017
@gchtr
Copy link
Member

gchtr commented Oct 16, 2017

@gsalkin Documentation for the reference is auto-generated from the DocBlocks of the PHP files. So to change the examples for Timber\Site, you’d have to edit the DocBlocks directly and submit a pull request for that, e.g. here:

* $context['other_site'] = new TimberSite($other_site_id);

There are still a lot of areas where the documentation has to be completed, especially in the class reference. So pull requests are very welcome! 😊

@gsalkin
Copy link
Author

gsalkin commented Oct 16, 2017

Good to know. Strangely, the Timber starter theme is using the old, non-namespaced version of timber functions like TimberPost or TimberSite. Is there some kind of backwards compatibility going on that my site isn't taking advantage of? Perhaps I've stumbled on to a larger set of enhancements for the project currently ongoing?

@gsalkin
Copy link
Author

gsalkin commented Oct 16, 2017

@drskullster By the by, updating with Namespacing does not seem to have worked. Still same errors.

Are ALL references to Timber required to be renamed to Timber\Timber?

For example: Timber::get_context() becomes Timber\Timber::get_context()?

I guess I'm confused my old non-namespaced functions are still working on the VM but not in the staging environment. Is there a possibility this is related to an issue in my deployment process?

@drskullster
Copy link

@gsalkin yes, every time you're using the class Timber you'll have to namespace it.

An alternative would be to insert a use statement at the beginning of your php file. You'll also have to add a statement for each class you're using :

use Timber\Timber;
use Timber\Post;
use Timber\Site;
...
Timber::get_context();
...
class MySite extends Site {}
...
new Post();

As a side note, if you're feeling nostalgic about the old class names you could do something like :

use Timber\Post as TimberPost;
...
new TimberPost();

@gsalkin
Copy link
Author

gsalkin commented Oct 17, 2017

@drskullster very helpful, thanks. Still find it strange that documentation and the starter theme haven't been updated with this namespacing change. Makes it hard to accurately replicate code. @jarednova @gchtr is there something I'm missing here?

@nlemoine nlemoine closed this as completed Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants