LeonLatex Posted August 5, 2022 Share Posted August 5, 2022 (edited) I think i got some trouble with the code pasted below: include __DIR__ . '/../Templates/' Is it correct with a space before and after the period or not? Edited August 5, 2022 by LeonLatex Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/ Share on other sites More sharing options...
requinix Posted August 5, 2022 Share Posted August 5, 2022 Dump the value of __DIR__ so you can see what it ends with. You can assume that's mostly always going to be the case. Then consider whether there are possible exceptions to that. Then realize that having doubled-up slashes doesn't cause any problems. Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1598985 Share on other sites More sharing options...
LeonLatex Posted August 5, 2022 Author Share Posted August 5, 2022 (edited) Drop the value of dir? or do you mean that I should not use __DIR__ at all. What do you suggest I use as a replacement? Edited August 5, 2022 by LeonLatex Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1598986 Share on other sites More sharing options...
maxxd Posted August 5, 2022 Share Posted August 5, 2022 Not 'drop', 'dump'. Completely different thing in this context: https://www.php.net/manual/en/function.var-dump.php Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1598987 Share on other sites More sharing options...
Phi11W Posted August 5, 2022 Share Posted August 5, 2022 5 hours ago, LeonLatex said: include __DIR__ . '/../Templates/' Is it correct with a space before and after the period or not? The period is the String concatenation operator and PHP isn't fussy about having whitespace around its operators so it should work with either. Personally, I like the spaces. Other people I work with detest them. Go with whichever fits your Coding Standards. 😉 Personally, I would also question the use of ".." in your paths. To me, it suggests that you should be "anchoring" your paths "further up" the directory tree. As it is, you're making assumptions about what's "outside" the directory your script lives in and, if you refactored and moved things around, you could end up breaking things. (That said, this might just be a hang-over from my spending too many years writing ASP running under IIS). Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1598993 Share on other sites More sharing options...
Barand Posted August 5, 2022 Share Posted August 5, 2022 15 minutes ago, Phi11W said: Personally, I like the spaces. Me too. I think a small but important operator like that gets lost without the whitespace. Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1598996 Share on other sites More sharing options...
LeonLatex Posted August 5, 2022 Author Share Posted August 5, 2022 (edited) Ok, I like to have spaces too. It makes it more....... readable if you understand what I mean. I was not sure if it was this making the problem for me. If it depends if there is a space or not. Now I know for sure it is not here the problem is. I haven't looked into it today, so I don't know where the error is. But hope I find the error today. Thanks for helping me out and making it clear. I will look in ti your suggestion and see if I find out about this too. I bet you are into security reasons....🤔 Stressful day. 🤪This was awfully bad English. Anyway, I hope you understand. Edited August 5, 2022 by LeonLatex Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1599011 Share on other sites More sharing options...
LeonLatex Posted August 5, 2022 Author Share Posted August 5, 2022 11 hours ago, Barand said: Me too. I think a small but important operator like that gets lost without the whitespace. As I already said, it makes it easier and more readable with white spaces. I feel it that way. So, when possible, I put in a white space where I can. What about this block: <?php function loadTemplate($templateFileName, $variables = []) { extract($variables); ob_start(); include __DIR__.'/../templates/' .$templateFileName; return ob_get_clean(); } Can I have a space between the period/dot and $ here too? .$templateFileName; Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1599039 Share on other sites More sharing options...
Barand Posted August 5, 2022 Share Posted August 5, 2022 12 hours ago, Phi11W said: The period is the String concatenation operator and PHP isn't fussy about having whitespace around its operators so it should work with either. Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1599040 Share on other sites More sharing options...
ginerjm Posted August 5, 2022 Share Posted August 5, 2022 Or like this: include __DIR__ . "/../templates/$templateFileName"; Quote Link to comment https://forums.phpfreaks.com/topic/315140-space-before-perode-or-not/#findComment-1599041 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.