ID:               20601
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 Status:           Open
 Bug Type:         Documentation problem
 Operating System: Windows ME
 PHP Version:      4.3.0RC1
 Assigned To:      philip
 New Comment:

Sort of.  This is a feature I was not aware of in PHP and imho is sort
of a bug :)  

As it turns out, constants are only seen in strings if:

a) It's an array key
b) {braces} are around the array

So for example, NO E_NOTICE is generated from "a $arr[foo]"  but "a
{$arr[foo]}" does!  And btw, "a {foo}" does not look for the constant
foo.

And because multidimensional arrays inside strings require {braces}
this is an important point.  IMHO this behavior of constants inside
strings is inconsistent and I'm writing php-dev now! :)


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

[2002-12-17 10:37:35] [EMAIL PROTECTED]

Philip, please do not change that part of the documentation. **It is
correct!**.

Try with this script:

<?php

error_reporting(E_ALL);
ini_set("display_errors", TRUE);

$arr['foo'][3] = 14;

echo "This is wrong: {$arr[foo][3]}";
echo "This is good: {$arr['foo'][3]}";

?>

For the first echo line, a NOTICE error is
echoed out... So the documentation is correct. It may not be clear
enough, but it is correct, the example is right.

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

[2002-12-05 13:49:27] [EMAIL PROTECTED]

As it turns out, the string docs are wrong and contain the following in
the example:


// This is wrong for the same reason
// as $foo[bar] is wrong outside a string. 
echo "This is wrong: {$arr[foo][3]}";


I'll rewrite this part of the documention too.  $foo[bar] is perfectly
fine inside strings, CONSTANTS aren't seen in strings.  Anyway, this
will be further explained with a more specific example too.  And a faq
entry :)  This question comes up waaaaaaay too much these days.

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

[2002-12-05 13:26:22] [EMAIL PROTECTED]

The string type description includes a lengthy explanation of this
AFAIK.

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

[2002-12-04 19:03:14] [EMAIL PROTECTED]

Btw, this happens when you do:

print "a foo $bar['blah'] eh";

Don't do that.  You can do either:

print "a foo {$bar['blah']} eh";
print "a foo $bar[blah] eh";
print "a foo " . $bar['blah'] . " eh";

But when outside of strings always quote your keys:

print $bar[blah];   // bad
print $bar['blah']; // good

Unless of course you defined blah as a constant earlier.  Anyway I'm
making a faq out of this question and marking as a doc bug because this
question comes up a lot especially since 4.1.0 (autoglobals) and 4.2.0
(register_globals default change).

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

[2002-12-04 18:17:54] [EMAIL PROTECTED]

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.



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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/20601

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


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to