Right today I decided to move my files offline on to test site... I already have a test site on my aptop using xampp... but its not the same as the online one it has some different modules but not many... a few for mail... anyways... I decided I would get the files offline and put them on my pc and start using that in future to develope websites s that in future my pc will be my main work computer as there is just to much distraction on my laptop. An plus the pc is in my office room... Just so you know why.
Anyways to the point when I moved the site I kept getting error "Parse error: syntax error, unexpected $end in C:\xampp\htdocs\websites\Drupal\sites\all\themes\beach\page-node.tpl.php on line 250". At first I just assumed it was me doing it wrong... and it was very frustrating though i had trasfered files wrong... had copied wrong mysql files... then i decided I would check out the error happened to stumble on something about globals... I didnt read it all which I will in a second but I think its unrelated just a cowincidence... I just finished reading it... its on adding globals in tpl... An why not to do it... but doesnt explain why it works on my domain and on my laptop development test site... it makes no sense... Although it is slighlty related...
So I removerd the following code:
<?php
global $user;
$userId = $user->uid;
if (in_array('unactivated user', array_values($user->roles))) {
?>
<div class="activation-alert" align="center">
<p>You need to activate your account before you can use this site. <br />
Please go to your email and click the activation link to be able to use this site. <br />
If you don't do so your account will be deleted with in a week from creation.<br />
If you never recieved a Activation E-mail for some reason, please <a href="<? print $base_path ?>toboggan/revalidate/<?= $userId ?>"> click here</a> to resend.</p>
</div>
<? }?>
For some reason this was throwing my template out of wake... on my pc... I find it very odd... Does anyone know why it does this am using xammp on my pc computer to? I think its odd... that it has done this? If I find out the answer I will post it I just though it might be handy for anyone else who used a global... to know...
I will play about now on the other one see if I can get it working with this code... Its strange :S
Comments
Ok so I worked out that its
Ok so I worked out that its nothing to do with the "global $user;" and "$userId = $user->uid;"...
What I find most strange is that it was working fine before but on this computer its not...
Worked out reason... but don't know why?
The reason is this if statment:
if (in_array('unactivated user', array_values($user->roles))) {
}
Does anyone know why this is happening? all of the sudden?
here's the story:
The code you pasted there contains a mix of php short-tags
<? ?>, as well as the correct long tags<?php ?>.PHP short tags are an optional syntax, but discouraged and they are allowed on a per-server basis - a flag in your php.ini.
This is why it works on one site but not on another. Also why their use is discouraged.
Some themes leave these in by accident because the coder wasn't aware of the conventions.
You could enable the short-tags option if you need to support legacy PHP scripts, but the fix is to change
<?to<?phpanywhere it occurs.The syntax error you see is due to the interpreter not being able to find the correct closing
?>tag for the statement on the line listed.You owe me a beer ;-)
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Life saver :) If you live
Life saver :)
If you live close by I definatly do owe you a beer...
An I got a Valuable lesson... Writes on postet note... "Don't use short tags you fricking moron" haha
I assumed that short tags was fine if not much code was writen how wrong was I.
Thanks a lot!
Just got me thinking tho that
Just got me thinking tho that was one hell of a cowinsidence... that I ended up getting that code out because I though it was global and it was totally unrelated... Its little odd... Makes me wonder. think I was very lucky to realise where the problem was... Strangeness
FYI
Buried in documentation.
But it's not the sort of thing you'd know matters unless you knew to ask the question in the first place, so it's a bit of a blind spot to semi-experienced PHP devs.
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Well everything I know about
Well everything I know about php I learned myself, from watching videos or playing about... An I remember somewhere reading somewhere always use <?php but I assumed it was just for structle reason not to stop errors... How wrong was I but I bow down and gracisly accept that I was wrong there... haha, Guess I never had a bug with it to in order to ingrave it in my mind when coding haha wont make that school boy error again.
To be fair am not the strongest php programmer I never got to grips with deep stuff something I really want to learn though... once I achieve that I would be a very happy man. I mean I know arrays... loops, calls to myspl, lot basic stuff... but nothing amensly complex that turns 200 lines of code in to 3 paragraphs thats something I would love to be able to do.
No disrespect intended. It's
No disrespect intended. It's just one of those things you learn after moving from system to system a few times, you never realize what part of coding was an assumption (like file path separators going / or \ or : ) until you've moved your code around a few times. So it's totally forgivable ;-) PHP versions have a lot of cruft like this. It can be configured to be a very forgiving language, but like happened with HTML, that let a lot of lazy habits creep in.
This is one of those ones that never would have bitten you if you were only ever using one server or distribution. This sort of stuff actually makes up a large portion of the time I spend coding for OSS - I can get it to work for me in 20 minutes, but to get it to work for everybody without knowing how their server is configured takes another hour of bullet-proofing and testing :-)
.dan. is the New Zealand Drupal Developer working on Government Web Standards