Re: Cannot use "-" in variable names?
ross said the following on 10/12/2005 14:31:
> Kimmo Laine wrote:
>
>> "ross" <aoxo_oxoa@yahoo.com> kirjoitti
>> viestissä:dncl4u$hl4$1@mailhub227.itcs.purdue.edu. ..
>>
>>> I understand that the "-" sign is seen as an operator.
>>> is there a way to get around this? I need to have "-" in variable names.
>>
>>
>>
>> I'd very much like to hear why you _need_ to use such a poor naming
>> practise. I'd understund if you _want_ to use such, but not that you
>> really really absolutely _need_ to use such. And my apologies, I'm
>> just a really curious person. :)
>>
>>
> I am parsing a xml file and would like to create variables on the fly
> with the same name as the XML tags. some of the xml tags are in the
> form "xx-yy" etc.
Well firstly, that's dangerous. If someone created an XML document that
(accidentally or maliciously) contained elements with the same name as
existing PHP variables, you'd be screwed.
Secondly, what's the advantage in creating the variables on the fly?
Presumably you know the intended structure of the incoming the XML
document, otherwise there'd be no point in processing it. Therefore,
what's wrong with explicitly assigning values to variables as you parse
them? That way, you can avoid the problem I mentioned above.
--
Oli
|