OM2 Posted July 27, 2008 Share Posted July 27, 2008 Does it matter where I declare my variables? I have some code where I declare variables (in an array) that will be used globally. I have some code further below that I want to take out and put into another file. This will help in readability and updating that code. The code though, uses the global variables. Now, out of a matter of habit, I like to put my include staments right at the top. If I did this though: the code would access variables that are only declared below. Hope that makes sense. I know in a lot of languages: it doesn't matter. Wasn't sure what the case was this PHP, so I thought I'd check. Let me know. Thanks. OM Quote Link to comment https://forums.phpfreaks.com/topic/116864-solved-does-it-matter-where-i-declare-my-variables/ Share on other sites More sharing options...
trq Posted July 27, 2008 Share Posted July 27, 2008 PHP reads from the top down, so yes you cannot use variables untill after they are declared. Quote Link to comment https://forums.phpfreaks.com/topic/116864-solved-does-it-matter-where-i-declare-my-variables/#findComment-600922 Share on other sites More sharing options...
OM2 Posted July 27, 2008 Author Share Posted July 27, 2008 thanks for that. Quote Link to comment https://forums.phpfreaks.com/topic/116864-solved-does-it-matter-where-i-declare-my-variables/#findComment-600939 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.