php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77704 constant with namespace is not fetchable
Submitted: 2019-03-06 10:32 UTC Modified: 2019-03-06 12:32 UTC
From: eglic at ziima dot cn Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.15 OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: eglic at ziima dot cn
New email:
PHP Version: OS:

 

 [2019-03-06 10:32 UTC] eglic at ziima dot cn
Description:
------------
in php-7.2.15 source 'Zend/zend_constants.c':

ZEND_API int zend_register_constant(zend_constant *c)
{
...
#479  char *slash = strrchr(ZSTR_VAL(c->name), '\\');
...
#482  zend_str_tolower(ZSTR_VAL(lowercase_name), slash - ZSTR_VAL(c->name));

-----------
 constant name is changed to "foo\\BAR"

but in the same file 
#243   ZEND_API zval *zend_get_constant_str(const char *name, size_t name_len)
...
#250  zend_str_tolower_copy(lcname, name, name_len);

---------
use "Foo\\BAR" to find first,and try "foo\\bar" again.
both faied.
  

Test script:
---------------
1. REGISTER_NS_STRING_CONSTANT("Foo", "BAR", "Test", CONST_CS | CONST_PERSISTENT);
2. zval *c = zend_get_constant_str(ZEND_STRL("Foo\\BAR"));

it returns NULL;



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-06 12:32 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2019-03-06 12:32 UTC] cmb@php.net
> constant name is changed to "foo\\BAR"

Indeed, so you should use:

zval *c = zend_get_constant_str(ZEND_STRL("foo\\BAR"));
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 12:01:31 2025 UTC