php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23943 REGISTER_*_CONSTANT and sizeof to calculate length of constant name
Submitted: 2003-06-01 18:33 UTC Modified: 2003-06-29 20:09 UTC
From: eddie at omegaware dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.2 OS:
Private report: No CVE-ID: None
 [2003-06-01 18:33 UTC] eddie at omegaware dot com
Is there any reason why the REGISTER_*_CONSTANT macros (ie REGISTER_LONG_CONSTANT) use sizeof instead of strlen for calculating the length of the constant name? I am running into problems which resort to me having to not use this macros to define functions but to use the raw zend_register_*_constant function..

example.

using the macro with a literal string for the name works fine.

REGISTER_LONG_CONSTANT("MYCONSTANT",4567,CONST_CS|CONST_PERISISTENT);

however using the macro with a char * variable does not.

char *name = "MYCONSTANT";
REGISTER_LONG_CONSTANT(name,4567,CONST_CS|CONST_PERSISTENT);

The later results with the name_len variable to zend_register_long_contant being 4, the size of the char *.

This has caused me problems when I was trying to register a char* array of constants.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-01 18:35 UTC] eddie at omegaware dot com
fixed the summary field..
 [2003-06-01 20:37 UTC] sniper@php.net
Because the macro expects static string. Not bug.

 [2003-06-01 21:20 UTC] sniper@php.net
Nevermind..

 [2003-06-29 20:09 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

If the name of the constant is variable as it happens if your situations you should use zend_register function as you have already figured out. This is not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC