CodeIgniter Forums
Should the variable type for language keywords be static or const? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Should the variable type for language keywords be static or const? (/showthread.php?tid=91929)



Should the variable type for language keywords be static or const? - kuzeyybora - 11-11-2024

Hello everyone,

I'm designing a multilingual project, and I created a folder named Constants with a file called LanguageKeys.php inside it. The structure looks like this:
PHP Code:
namespace App\Constants
class 
LanguageKeys 
  public const ALLOWED_LOCALS = ["tr""en""de"]; 
  public const SUCCESS 'RESPONSE_SUCCESSFULLY_MESSAGE'
  public const FAIL 'RESPONSE_UNSUCCESSFULLY_MESSAGE'
  public const CREATE_SUCCESS 'RESPONSE_CREATE_SUCCESSFULLY_MESSAGE'

Do you think these should stay as they are, or would it be better to make them
public static instead? These keys are saved to Redis from the database, and unless revalidation is done, the data is queried from Redis.
Do you have any suggestions or thoughts on this?


RE: Should the variable type for language keywords be static or const? - InsiteFX - 11-11-2024

KISS & DRY
Your repeating yourself.
PHP Code:
public array $supportedLocales = ['en''es''fr-FR']; 

Config files only uses strings for output.