kreativmonkey Posted January 23, 2017 Share Posted January 23, 2017 I have some code in my template that works fine for my. Now i upgrade to 3.0.4 and i've got this error: Parse error: syntax error, unexpected ':', expecting ',' or ')' in processwire/dev/site/assets/cache/FileCompiler/site/templates/_function.inc on line 106 The code on my _function.php is a short if else: $template = $small ? new TemplateFile($config->paths->templates . "markup/events.inc") : new TemplateFile($config->paths->templates . "markup/event.inc"); PHP Version: 5.6 and 7 shows the same issue. On my productive installation the code works fine with the same PHP Versions (Processwire 2.6.0). What has changed that the code no longer works? Link to comment Share on other sites More sharing options...
gebeer Posted January 23, 2017 Share Posted January 23, 2017 Do you have <?php namespace ProcessWire; in the top of your _function.inc? Link to comment Share on other sites More sharing options...
kongondo Posted January 23, 2017 Share Posted January 23, 2017 11 minutes ago, gebeer said: Do you have <?php namespace ProcessWire; in the top of your _function.inc? I'm curious why this matters in the present circumstance? Link to comment Share on other sites More sharing options...
gebeer Posted January 23, 2017 Share Posted January 23, 2017 @kongondo guess you're right. I recently had problems upgrading to 3.x and found that putting the namespace in every file in my templates helped. But here it seems to be a syntax error. I couldn't spot it in the code provided so I wanted to make sure that it is not a compiling issue because of missing namespace. Link to comment Share on other sites More sharing options...
kongondo Posted January 23, 2017 Share Posted January 23, 2017 I see. My point was that the compiler is supposed to take care of cases where a 'namespace' has not been declared (and it does so beautifully). It seems in this case something is tripping it. Although namespacing, in this case, might get around the problem, it will not solve the original issue. It would be helpful to get to the bottom of that since not everyone is able/willing to namespace (especially in existing sites) their template files. I'm wondering whether it is the '.inc.' that is throwing it off or the use of double quotes. Just guessing TBH. Link to comment Share on other sites More sharing options...
kreativmonkey Posted January 23, 2017 Author Share Posted January 23, 2017 @gebeer no i don't add some lines to my code i only update processwire to 3.x not more. I don't touch my code between the update and the code works for me for 2 years.... When i add the namespace i must change some of my code right? I add the line to the function.php and this happened: Fatal error: Uncaught Error: Call to undefined function renderSidebar() in processwire/dev/site/assets/cache/FileCompiler/site/templates/home.php:75 Stack trace: #0 processwire/dev/wire/core/TemplateFile.php(268): require() #1 [internal function]: ProcessWire\TemplateFile->___render() #2 processwire/dev/wire/core/Wire.php(374): call_user_func_array(Array, Array) #3 processwire/dev/wire/core/WireHooks.php(549): ProcessWire\Wire->_callMethod('___render', Array) #4 processwire/dev/wire/core/Wire.php(399): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array) #5 processwire/dev/wire/modules/PageRender.module(514): ProcessWire\Wire->__call('render', Array) #6 [internal function]: ProcessWire\PageRender->___renderPage(Object(ProcessWire\HookEvent)) #7 processwire/dev/wire/core/Wire.php(374): call_user_func_array(Array, Array) #8 / in processwire/www.mta-r.de/dev/site/assets/cache/FileCompiler/site/templates/home.php on line 75 Link to comment Share on other sites More sharing options...
gebeer Posted January 23, 2017 Share Posted January 23, 2017 @kreativmonkey The thing is when you upgrade to 3.x and declare the namespace only in one file, it will most likely not work. You'd have to put the namespace line on top of all of your template files. Since the namespace is not declared in home.php but in function.php the file compiler in PW 3.x runs into errors. So either declare the namespace in all template files or in none. @all Please correct me if my assumption is wrong. At least this is how I understand it. When upgrading to 3.x it is a good idea to read up on PHP namespaces and search the forum for related threads. The error message in your first post points towards a syntax problem. But I can't spot an error in your syntax. Maybe someone else? Link to comment Share on other sites More sharing options...
matjazp Posted January 23, 2017 Share Posted January 23, 2017 Could you try simple if/else instead of ternary: if($small) $template = new TemplateFile($config->paths->templates . "markup/events.inc"); else $template = new TemplateFile($config->paths->templates . "markup/event.inc"); Link to comment Share on other sites More sharing options...
adrian Posted January 23, 2017 Share Posted January 23, 2017 @kreativmonkey - I would also recommend upgrading the to latest stable, if not the latest dev. 3.0.4 is very old now and there have been many bug fixes and especially, lots of improvements to the file compiler. 1 Link to comment Share on other sites More sharing options...
kreativmonkey Posted January 27, 2017 Author Share Posted January 27, 2017 On 23.1.2017 at 3:58 PM, matjazp said: Could you try simple if/else instead of ternary: if($small) $template = new TemplateFile($config->paths->templates . "markup/events.inc"); else $template = new TemplateFile($config->paths->templates . "markup/event.inc"); Yes if i use normal if/else the code will accepted. But why dose the code never work with the new PW? On 23.1.2017 at 4:31 PM, adrian said: @kreativmonkey - I would also recommend upgrading the to latest stable, if not the latest dev. 3.0.4 is very old now and there have been many bug fixes and especially, lots of improvements to the file compiler. Hi @adrian, i updateted to the 3.0.42 sorry for the confusion! I use the new ProcessWire Core (Master). @gebeer, i don't know if the PHP namespace solve my issue, it is a lot of work to include it on all template files and i think it is not the best practice, right? Link to comment Share on other sites More sharing options...
gebeer Posted January 28, 2017 Share Posted January 28, 2017 @kreativmonkey you can leave out the namespace if the site works. You would need them if you were using other PHP libraries inside ProcessWire that might have naming conflicts. Otherwise you don't need them to make PW work. But in general it is a good practice to use namespaces if you are know what the implications are. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now