{"id":2881,"date":"2022-08-30T15:28:33","date_gmt":"2022-08-30T15:28:33","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/07\/smarty-allow_php_tag-reports-undefined-property-smartyallow_php_tag-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:28:33","modified_gmt":"2022-08-30T15:28:33","slug":"smarty-allow_php_tag-reports-undefined-property-smartyallow_php_tag-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/smarty-allow_php_tag-reports-undefined-property-smartyallow_php_tag-collection-of-common-programming-errors\/","title":{"rendered":"Smarty allow_php_tag reports &#39;Undefined property: Smarty::$allow_php_tag&#39;-Collection of common programming errors"},"content":{"rendered":"<p>So I have an old website which uses an older version of smarty, as today I wanted to upgrade to latest version, and it hit&#8217;s me with an error:<\/p>\n<pre><code>[Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Notice:  Undefined property: Smarty::$allow_php_tag in \/work\/smarty3.1rc1\/Smarty.class.php on line 592\n[Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Fatal error:  Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template \"\/work\/templates\/modules\/main_module.tpl\"  on line 2 \"{php}\" unknown tag \"php\"' in \/work\/smarty3.1rc1\/sysplugins\/smarty_internal_templatecompilerbase.php:596\nStack trace:\n    #0 \/work\/smarty3.1rc1\/sysplugins\/smarty_internal_templatecompilerbase.php(382): Smarty_Internal_TemplateCompilerBase-&gt;trigger_template_error('unknown tag \"ph...', 2)\n    #1 \/work\/smarty3.1rc1\/sysplugins\/smarty_internal_templateparser.php(2383): Smarty_Internal_TemplateCompilerBase-&gt;compileTag('php', Array)\n    #2 \/work\/smarty3.1rc1\/sysplugins\/smarty_internal_templateparser.php(2865): Smarty_Internal_Templateparser-&gt;yy_r38()\n    #3 \/work\/smarty3.1rc1\/sysplugins\/smarty_internal_templateparser.php(2965): Smarty_Internal_Templateparser-&gt;yy_reduce(38)\n    #4 in \/work\/smarty3.1rc1\/sysplugins\/smarty_internal_templatecompilerbase.php on line 596\n<\/code><\/pre>\n<p>Even if I put Smarty 3.0.8 I get same errors &#8230; Since the website if full of <code>{php}<\/code> tags, removing is not an option. What can I do?<\/p>\n<p>Ok, as following @Pekka&#8217;s instructions i found out about Smarty Security Next problem:<\/p>\n<pre><code>$my_security_policy = new Smarty_Security($smarty);\n$my_security_policy-&gt;allow_php_tag = true;\n$my_security_policy-&gt;php_functions = array();\n$my_security_policy-&gt;php_handling = Smarty::PHP_PASSTHRU;\n$my_security_policy-&gt;php_modifier = array();\n$my_security_policy-&gt;modifiers = array();\n\n$smarty-&gt;enableSecurity($my_security_policy);\n<\/code><\/pre>\n<p>shouts:<\/p>\n<pre><code>[Fri Aug 19 12:06:40 2011] [error] [client ***.***.***.***] PHP Fatal error:  Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template .....' modifier 'strtolower' not allowed by security setting'\n<\/code><\/pre>\n<p>what&#8217;s wrong now &#8230; <code>$my_security_policy-&gt;php_functions = array();<\/code> allows all php functions ..<\/p>\n<ol>\n<li>\n<p>According to the docs, <code>allow_php_tag<\/code> is now a property of the <code>Smarty_Security<\/code> class, not <code>Smarty<\/code>. See the page for an example how to use it.<\/p>\n<p>I don&#8217;t know when this changed, but it&#8217;s probable it&#8217;s a new V3 feature. And a nice one at that!<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-03-07 11:16:01. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>So I have an old website which uses an older version of smarty, as today I wanted to upgrade to latest version, and it hit&#8217;s me with an error: [Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] PHP Notice: Undefined property: Smarty::$allow_php_tag in \/work\/smarty3.1rc1\/Smarty.class.php on line 592 [Fri Aug 19 11:21:19 2011] [error] [client ***.***.***.***] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2881","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2881"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2881\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}