Constant v Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steakpie
Forum Newbie
Posts: 7
Joined: Sat Apr 19, 2008 8:39 pm

Constant v Array

Post by steakpie »

Hi folks,

For a little project I am working on, I am making a language file. I have got about a quater of the way through taking any text from my script and into this file and have been doing using constants.

Before I go any further, does anyone know what will be quicker / efficient, a loads of constants, or a large lannguage array?

To me, they would just be about the same as they will both need about as many lines, however I am inexperienced and would appreciate the opinion of others more expereinced.

Cheers folks :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Constant v Array

Post by pickle »

I'd suggest using a global array. That's what is done most often in multi-language apps/sites.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Constant v Array

Post by s.dot »

Right. You'll need it in a global array because you may need it in different scopes. Constants are available in all scopes, but in my opinion arrays are easier to work with. Also, I remember reading somewhere that constants are slow... but I don't remember where so I can't back that statement up.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Constant v Array

Post by Benjamin »

I've ran tests before on constants vs arrays and there was a difference but nothing significant.

I think a unique solution would be to have keys for each word that would be parsed out and replaced depending on the language before the html is sent to the browser. With this method keys could be anywhere, in the html or database, and would automagically get rendered.
steakpie
Forum Newbie
Posts: 7
Joined: Sat Apr 19, 2008 8:39 pm

Re: Constant v Array

Post by steakpie »

Actions, how do you mean keys?

Like ~~MESSAGE~~ ?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Constant v Array

Post by Benjamin »

Yeah, like {$WELCOME_MESSAGE}
Post Reply