note 129174 added to language.namespaces.global

From: Date: Thu, 18 Jan 2024 15:24:14 +0000
Subject: note 129174 added to language.namespaces.global
Groups: php.notes 
Request: Send a blank email to php-notes+get-221128@lists.php.net to get a copy of this message
To define an associative array (hash) so that it is part of the namespace, instead of going into the global namespace, just declare it as const, istead of as a variable. This is handy for lookup tables, config settings, etc. // Example. Instead of writing: $my_datatypes = [ "sterility" => [ "xlsx" => [ "Sample Type", "Run Pass/Fail", "Result" ], "db" => [ "SampleType", "RunPassFail", "Result" ] ] ]; // ...declare the lookup table like this: const MY_DATATYPES = [ "sterility" => [ "xlsx" => [ "Sample Type", "Run Pass/Fail", "Result" ], "db" => [ "SampleType", "RunPassFail", "Result" ] ] ]; // ...and it will be declared within the current namespace. ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 131.111.84.193) ---- Manual Page -- https://php.net/manual/en/language.namespaces.global.php Edit -- https://main.php.net/note/edit/129174 Del: integrated -- https://main.php.net/note/delete/129174/integrated Del: useless -- https://main.php.net/note/delete/129174/useless Del: bad code -- https://main.php.net/note/delete/129174/bad+code Del: spam -- https://main.php.net/note/delete/129174/spam Del: non-english -- https://main.php.net/note/delete/129174/non-english Del: in docs -- https://main.php.net/note/delete/129174/in+docs Del: other reasons-- https://main.php.net/note/delete/129174 Reject -- https://main.php.net/note/reject/129174 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221128) next »