{"id":3179,"date":"2022-03-28T15:32:29","date_gmt":"2022-03-28T14:32:29","guid":{"rendered":"https:\/\/www.simonbattersby.com\/blog\/?p=3179"},"modified":"2022-05-04T08:20:40","modified_gmt":"2022-05-04T07:20:40","slug":"opencart-the-twig_autoloader-class-is-deprecated-error","status":"publish","type":"post","link":"https:\/\/www.simonbattersby.com\/blog\/2022\/03\/opencart-the-twig_autoloader-class-is-deprecated-error\/","title":{"rendered":"Opencart &#8211; &#8216;The Twig_Autoloader class is deprecated&#8230;&#8217; error"},"content":{"rendered":"<p>I was contacted by a client last week who was getting this error message on her site.<\/p>\r\n\r\n<p>It appears on Opencart 3.x up to 3.0.3.5, and is caused by an older version of the Twig template engine not playing nicely with PHP 8. Thus the problem often occurs if your hosting company has upgraded your PHP version without telling you. Searching for the error mainly finds a number of sites with the same issue, plus a number of threads on the (sadly rather unhelpful and not uncommonly abusive) Opencart forums, none of which have what I think is a clear answer. So, for the benefit of others, here are your options if this happens to you:<\/p>\r\n\r\n<h2>Update your Opencart version<\/h2>\r\n\r\n<p>This is the best option. Upgrading from 3.x to a newer version is relatively straightforward and documented elsewhere.<\/p>\r\n\r\n<h2>Revert to an earlier version of PHP<\/h2>\r\n\r\n<p>This is good for a quick fix, and is generally done from your hosting Control Panel. If your hosting provides cPanel, then it&#8217;s accessed via MultiPHPManager. Find the affected domain, and change the PHP version from 8 to 7.4. Apply the change and your errors should have disappeared.<\/p>\r\n\r\nTo restate, this is just a temporary fix as at some point in the future your hosting company may remove the option to run PHP7.<\/p>\r\n\r\n<h2>Manually update files on the server<\/h2>\r\n\r\n<p>At this point all the purists will be throwing their hands in the air and listing lots of reasons why this is bad idea. However, we live in the real world, and it may be you have multiple hard coded customisations on your install, and you really don&#8217;t want to take any risks. If this is the case, read on, this is what I did:<\/p>\r\n\r\n<ol class=\"bulletlist\">\r\n<li>Take whatever backups of your filesystem and database you need to sleep soundly<\/li>\r\n<li>Download a copy for the latest Opencart (3.0.3.8 at the time of writing) to your PC<\/li>\r\n<li>From your new download, upload the whole of the <code>system<\/code> folder <strong>on top<\/strong> of your current version.<\/li>\r\n\r\n<li>Similarly, upload the <code>catalog\/controller\/event\/theme.php<\/code> file on top of your current version<\/li>\r\n<li>If you currently have your storage folder outside your Opencart directory, edit <code>config.php<\/code> and <code>admin\/config.php<\/code> to set the storage folder back to <code>...system\/storage<\/code> withhin your Opencart directory<\/p>\r\n<\/ol>\r\n\r\n<p>And that&#8217;s it. You&#8217;ll want to run your own checks of course, but that worked for me.<\/p>\r\n<p>Opencart will prompt your to move your storage folder when you log in to admin.<\/p>\r\n<p>If for whatever reason you haven&#8217;t uploaded the <code>system<\/code> folder on top of the existing one, but deleted the old one instead, then you will get a different error complaining about Openbay. This is because Openbay support was removed in OC3.0.3.6. Assuming you don&#8217;t need this then find this line in both <code>catalog\/controller\/startup\/startup.php<\/code> and <code>admin\/controller\/startup\/startup.php<\/code>:\r\n\r\n<pre\t\t\/\/ OpenBay Pro\r\n\t\t\/\/$this->registry->set(&#8216;openbay&#8217;, new Openbay($this->registry));<\/pre>\r\n\r\n<p>and delete it or comment it out. <\/p>","protected":false},"excerpt":{"rendered":"<p>I was contacted by a client last week who was getting this error message on her site. It appears on Opencart 3.x up to 3.0.3.5, and is caused by an older version of the Twig template engine not playing nicely with PHP 8. Thus the problem often occurs if your hosting company has upgraded your [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[28],"class_list":["post-3179","post","type-post","status-publish","format-standard","hentry","category-web-design-and-build","tag-opencart"],"_links":{"self":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/posts\/3179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/comments?post=3179"}],"version-history":[{"count":13,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/posts\/3179\/revisions"}],"predecessor-version":[{"id":3199,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/posts\/3179\/revisions\/3199"}],"wp:attachment":[{"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/media?parent=3179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/categories?post=3179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.simonbattersby.com\/blog\/wp-json\/wp\/v2\/tags?post=3179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}