# REGISTER_*_CONSTANT() or SET_VAR_*() with multiple strings constants

- Thread: https://externals.io/message/6289
- Original archive: https://news-web.php.net/php.internals/6289
- Started by Justin Hannus on 2003-12-08T18:45:33+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #6289 — Justin Hannus — 2003-12-08T18:45:33+00:00

URL: https://externals.io/message/6289#6289

sent to php.pecl.dev and php.internals
--------------------------

I'm building an extension that will need to register multiple (approx 250
(up to 48 chars per string)) strings as constants. I would rather not
clutter up the namespace with all these constants so I was wondering what
would the recommended way to achieve this would be?

A. Should I normalize the constants by mapping them to int's and create a
few ZEND_FUNCTION(ext_import_*_constants) functions and use SET_VAR_LONG()
and internally have a static char *php_ext_map_constant(int c) that maps the
php int constants to a string?
B. Go all out and use REGISTER_STRING_CONSTANT[L]()  in the ext's startup?
C. Or, just create an include php file with all the constants `defined()`'d
from php code and distribute with ext or package as PEAR?
D. Ignore constants and let the users type the string themselves.

I noticed one other ext (syslog) that does something like this with
define_syslog_variables(). I also toyed with the idea of creating
zend_object's that hold these constant to avoid cluttering up the namespace
but I need this to work for php 4-5 and I'm not sure that 4 supports
read-only class variables. Any thoughts on this would be appreciated.
Thanks,

--
Justin Hannus
Lead Programmer/Web Development
jhannus@visualconceptsinc.com
www.visualconceptsinc.com
[860] 242.1150 ext.125
[860] 242.1446 fax

---

## #6294 — Andi Gutmans — 2003-12-09T08:32:02+00:00

URL: https://externals.io/message/6289#6294 · In reply to: #6289

I think that as long as you follow the naming standards for constants which 
are EXTNAME_CONSTANT it should be OK to just define them as regular global 
constants during MINIT.

Andi

At 01:45 PM 12/8/2003 -0500, Justin Hannus wrote:
>sent to php.pecl.dev and php.internals
>--------------------------
>
>I'm building an extension that will need to register multiple (approx 250
>(up to 48 chars per string)) strings as constants. I would rather not
>clutter up the namespace with all these constants so I was wondering what
>would the recommended way to achieve this would be?
>
>A. Should I normalize the constants by mapping them to int's and create a
>few ZEND_FUNCTION(ext_import_*_constants) functions and use SET_VAR_LONG()
>and internally have a static char *php_ext_map_constant(int c) that maps the
>php int constants to a string?
>B. Go all out and use REGISTER_STRING_CONSTANT[L]()  in the ext's startup?
>C. Or, just create an include php file with all the constants `defined()`'d
>from php code and distribute with ext or package as PEAR?
>D. Ignore constants and let the users type the string themselves.
>
>I noticed one other ext (syslog) that does something like this with
>define_syslog_variables(). I also toyed with the idea of creating
>zend_object's that hold these constant to avoid cluttering up the namespace
>but I need this to work for php 4-5 and I'm not sure that 4 supports
>read-only class variables. Any thoughts on this would be appreciated.
>Thanks,
>
>--
>Justin Hannus
>Lead Programmer/Web Development
>jhannus@visualconceptsinc.com
>www.visualconceptsinc.com
>[860] 242.1150 ext.125
>[860] 242.1446 fax
