php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25662 Bug in zend_fetch_constant_handler
Submitted: 2003-09-25 15:54 UTC Modified: 2003-09-26 05:38 UTC
From: cliff at may dot be Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2003-09-25 (dev) OS: Linux
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: cliff at may dot be
New email:
PHP Version: OS:

 

 [2003-09-25 15:54 UTC] cliff at may dot be
Description:
------------
When the wrong value is used for a constant, the error message repeats the erroneous constant in the warning.  I don't totally understand the code but it appears to be trying to use the erroneous value too.  So either just the second 
  EX(opline)->op2.u.constant.value.str.val
needs to be changed or the code needs fixing too.

Reproduce code:
---------------
if (!zend_get_constant(EX(opline)->op2.u.constant.value.str.val,
 EX(opline)->op2.u.constant.value.str.len, &EX_T(EX(opline)->result.u.var).tmp_v
ar TSRMLS_CC)) {
    zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", EX(opline)->op2.u.constant.value.str.val,     EX(opline)->op2.u.constant.value.str.val);
    EX_T(EX(opline)->result.u.var).tmp_var = EX(opline)->op2.u.constant;
zval_copy_ctor(&EX_T(EX(opline)->result.u.var).tmp_var);
}


Expected result:
----------------
Notice: Use of undefined constant EXTRACT_OVERWRITE - assumed 'EXTR_OVERWRITE' in ...

Actual result:
--------------
Notice: Use of undefined constant EXTRACT_OVERWRITE - assumed 'EXTRACT_OVERWRITE' in ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-25 16:45 UTC] abies@php.net
It assumes you meant (string)'EXTRACT_OVERWRITE' and uses that instead of the constant's value.


 [2003-09-25 18:10 UTC] cliff at may dot be
To what effect?  A string is not a legal value there.  IMHO, it should either use the default value or generate a fatal error.

Or am I missing something obvious?
 [2003-09-26 01:24 UTC] pollita@php.net
It's a tradeoff, treating non-existant constants like strings allows for syntax like:

echo $myarray[fooindex]

to work.  It also allows what is a technicly legal parse:

echo "The output says: " . FOO;

to use FOO as a constant (if it's defined) or fallback on string behavior if it's not.

As to functions which expect a certain range of constants, how is PHP to know what the correct constant is?  To a human a typo of EXTR / EXTRACT seems obvious, to a machine it's less clear.  

By treating the non-constant as a string, we ensure that it will convert to an integer value of zero in the evaluating function and raise a proper error which, in conjunction with the undefined constant notice, should be enough to prompt the scripter to fix their code.

Conversely, if we were to treat a non-constant as a complete lack of a value (allowing the function to perform its default behavior) the typo would be masked sending the scripter off on a wild goose chance hunting the "bug" down.
 [2003-09-26 05:38 UTC] cliff at may dot be
OK.  Point taken.  In that case I would simply suggest the message be made clearer, on the lines of:

"Use of undefined constant %s - using string '%s'"

Thanks for your explanation, by the way.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 26 22:00:03 2025 UTC