Variables versus constants versus associative arrays in PHP

I am working on a small project and must somehow implement internationalization. I’m thinking about how to use constants to define a large number of characters for text in a single file, which can later be included. However, I’m not sure if using variables is faster, or I can avoid using associative arrays without an excessive amount of performance hit.

What is better for determining constant values ​​in PHP, in terms of performance, are constants defined using define("FOO", "...")either simple type variables $foo = "..."or associative type arrays $symbols["FOO"]?

+3
source share
4 answers

There will be no noticeable difference in performance, so do not worry about it. Do everything that will be easier to maintain.

Personally, I would go with an associative array if it is not too complicated. If the situation is a little more complicated, use gettext.

+4
source

Think about gettext

This question is not related to performance.
No syntax issue (i.e., Constants and variables) can affect performance

+1
source

, , .

PHP define . , - PHP : http://pecl.php.net/package/hidef


, , .
ini , :

int N     = -191
str ABC   = "xyz"
float PIE = 3.1419
bool ART  = true

/ - (, )

+1

, Zend_Translate Zend_Locale, , (Zend_Date, Zend_Currency ..). , , (getext, tmx, csv, xliff ..),

0

Source: https://habr.com/ru/post/1743682/


All Articles