General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 23rd, 2003, 12:30 AM
Mojoman's Avatar
Mojoman Mojoman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 39 Mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 34 sec
Reputation Power: 6
Is it possible to have an include file with nothing but $variables?

Thanks in advance to the DevArticle community - you guys are the greatest!

Today's question - Let's say I have a table with fields that hold one or two digit number values that correspond to arrays like the one below:

$eyewearkey = array("Perfect Vision","Fasionable Glasses","Glasses to Read","Contact Lenses","Cheap Sunglasses","Rather Not Say","Glasses");

Throughout the site, there are many places where these variables are needed and I was wondering if they could reside within an include file?

- Mojoman
__________________
$mybrain = "mush";
-------------------------------------------
http://www.loftsboston.com
http://www.gregdawsondesign.com

Reply With Quote
  #2  
Old April 23rd, 2003, 01:21 AM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to avit
Most certainly!

Make a "config.php" file and put all of your global definitions in there... It's where things like $db_user, $db_pass, etc... should also be kept.

Reply With Quote
  #3  
Old April 23rd, 2003, 09:27 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
If you will be using these var's throughout functions, the norm is to create constants of them - your code in return will be alot cleaner:
PHP Code:
 define'CONST_NAME'$const_value ); 

Now, you can use the constant throughout your script, in functions or where ever by this ->
PHP Code:
echo( CONST_NAME ); 

The above would echo what ever is bound to the constant...
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #4  
Old April 23rd, 2003, 03:07 PM
torrent torrent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 19 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Couple of things about Constants. One is that they can only be scalars. Objects and arrays are not permitted.

Also, you can't use them in Here-docs (for obvious reasons). Other than that they are definitely the way to go.

Reply With Quote
  #5  
Old April 23rd, 2003, 03:42 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to avit
Quote:
Originally posted by torrent
Couple of things about Constants. One is that they can only be scalars. Objects and arrays are not permitted.

Also, you can't use them in Here-docs (for obvious reasons). Other than that they are definitely the way to go.


Yeah, I actually find it annoying that constants aren't prefixed by $ like variables... To me it somehow seems like it breaks format. (And as you pointed out, they are far more restrictive than plain variables.)

If you end up using variables instead of defining constants, just be careful with your assignment operators so you don't change something you didn't mean to:

PHP Code:
if ($password 'somestring') {
  
// will always return TRUE because you've
  // just assigned 'somestring' to your
  // $password variable!
}

if (
$password == 'somestring') {
  
// This is what you have to do.
  // I still sometimes mess up my
  // == (comparison) and = (assignment)...


Reply With Quote
  #6  
Old April 23rd, 2003, 04:24 PM
torrent torrent is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 19 torrent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
...and don't forget the ol'
PHP Code:
if ($foo === $bar



Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Is it possible to have an include file with nothing but $variables?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT