FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Why Can't I "define" a Value for a Subscript?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Why Can't I "define" a Value for a Subscript? [message #175243 is a reply to message #175241] Mon, 29 August 2011 00:26 Go to previous messageGo to previous message
Richard Damon is currently offline  Richard Damon
Messages: 58
Registered: August 2011
Karma:
Member
On 8/28/11 4:57 PM, eBob.com wrote:
>
> "Chuck Anderson" <cycletourist(at)invalid(dot)invalid> wrote in message
> news:j3e62a$p8k$1(at)dont-email(dot)me...
>> eBob.com wrote:
>>> I am working with some csv files. To make the program more
>>> maintainable and more self-documenting I "define" values to use as
>>> subscripts; e.g. ...
>>>
>>> define('SS2KEY',0);
>>>
>>> BUT, whereas this produces what I expected ...
>>>
>>> echo "we have a match - key: $file2cols[0]\n";
>>>
>>> ... this does not ...
>>>
>>> echo "we have a match - key: $file2cols[SS2KEY]\n";
>>>
>>> I see the other text but no value is substitited for $file2cols[SS2KEY]
>>>
>>> I've wasted so much time on this. Why can't I define constants to use
>>> as subscripts?
>>>
>>> Thanks, Bob
>>
>> Php does not look for constants within double quotes.
>>
>> http://www.php.net/manual/en/language.types.array.php
>> (Look for "Array do's and don'ts" - scroll down a wee bit for examples)
>>
>> --
>> *****************************
>> Chuck Anderson • Boulder, CO
>> http://cycletourist.com
>> Turn Off, Tune Out, Drop In
>> *****************************
>
> OUCH!!!!!!! But thanks! Now if I can only remember this "feature".
>
> Thanks, Bob

To understand why it is this way, just think about this program:

define('Hello', 'Goodbye cruel');
echo "Hello World";

Just looking at the echo statement, you should know what is printed, and
not need to scan the whole program to make sure nothing is going to
change your string.

if you see

echo "Hello $name";

the $ make it clear that the following will be substituted so there is
no surprise (if you know the language rules).
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Deploying PHP 5.3 on CentOS 5.6 with Puppet
Next Topic: Strategic Marketing Summit 2011 (September 24th,Chennai)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 12:59:59 GMT 2024

Total time taken to generate the page: 0.04882 seconds