Pergunta

As per discussion How to check if a string can be used as a variable name in PHP? the user TIM is giving there a good answer but still not solving my problem.

I am doing the call exactly like that, but on production server they have magic quotes gpc active! and.. of course.. i can't disable it, i can't ask to disable and last but not least, i can't disable it during runtime (as per manual). So in this case, even if using

echo $xml->example->{'phone-number-1'};

php is trying to execute a mathematical operation between that stuff and i am really becoming mad to understand how to access to that "node" in this case.

And of course, if i test this with magic quotes OFF, everything is ok as per manual.

Thank you in advance

Foi útil?

Solução

To elaborate on the comment made, with the information available that you want to share, your code works as advertised, regardless of whether magic_quotes_gpc is set or not. It will not attempt to perform any arithmetic on the strings, and magic_quotes_gpc will not affect the way simplexml parses it's data.

~/temp  ►  cat foo.xml
<example>
    <node-ex>
       <identifier-1>ValueOfIdentifier1</identifier-1>
       <phone-number-1>141 555 1414</phone-number-1>
    </node-ex>
</example>

~/temp  ►  cat test.php
<?php
$root = simplexml_load_file("foo.xml");

echo $root->{'node-ex'}->{'identifier-1'} . "\n";
echo $root->{'node-ex'}->{'phone-number-1'} . "\n";

~/temp  ►  php test.php              
ValueOfIdentifier1
141 555 1414
~/temp  ►  php -dmagic_quotes_gpc=1 test.php
ValueOfIdentifier1
141 555 1414

Of course, if your example isn't the same as the data you're actually using, that might be the issue. If magic_quotes_gpc is enabled, using stripslashes() should reverse it, and then it should work. If you're not using a constant string, but a variable -- that might be the cause of the issue. There is however nothing in your example that indicates anything that should be affected by either magic_quotes_gpc or using "-" in the property name.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top