ID:               25662
 Updated by:       [EMAIL PROTECTED]
 Reported By:      cliff at may dot be
 Status:           Bogus
 Bug Type:         Zend Engine 2 problem
 Operating System: Linux
 PHP Version:      5CVS-2003-09-25 (dev)
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2003-09-25 18:10:15] 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-25 16:45:41] [EMAIL PROTECTED]

It assumes you meant (string)'EXTRACT_OVERWRITE' and uses that instead
of the constant's value.



------------------------------------------------------------------------

[2003-09-25 15:54:48] 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 ...


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25662&edit=1

Reply via email to