2

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

Community
  • 1
  • 1
andymnc
  • 103
  • 7
  • 1
    It's not trying to execute any math here, that much I can guarantee. Are you sure the issue is related to magic quotes? Where is your input coming from to be affected by magic quotes? – deceze Dec 06 '12 at 11:55
  • To be able to say why magic_quotes are affecting the code you've added, we'll need a more complete example. The code shown will not perform a mathematical operation in its current form. – MatsLindh Dec 06 '12 at 12:21
  • I am at the end of the process and i just did million of tests, so.. yes i am sure about everything. So the question is: HOW SHOULD I CALL THAT NODE, WITH STRUCTURE LIKE: root->fields->field->node-number-1 and with magic quotes gpc = "ON" (server side) the call $xml->.....->{'node-number-1'}; in this case is not working. part of the xml is like: ... ......... 123 123456789 1 456789 ......... ... if i var_dump the object, it's NOT showing all of the nodes with the "-" – andymnc Dec 06 '12 at 14:47
  • I can't see how magic quotes would have any impact on this.... however, if you've got a production server with magic quotes on, then you've got a production server with a serious security issue. – SDC Dec 06 '12 at 14:53
  • you haven't shown us how you're generating the object structure from the XML. That would be useful to see. But if it isn't showing in `var_dump` then it means that the variable does not exist. It may be that the XML parser you're using has decided that the element cannot be generated as a valid PHP variablename, and is thus not creating it at all. But need to see more code to know more about that. – SDC Dec 06 '12 at 14:55

1 Answers1

0

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.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • can i ask you to write here an example with stripslashes about echo $root->{'node-ex'}->{'phone-number-1'}; – andymnc Dec 06 '12 at 15:36
  • Well, as there is no values here that gets applied anything with magic_quotes_gpc, there really isn't anything to call stripslashes on. This is kind of the point I'm trying to make, and why we need to have the context of your code in your example, as there is nothing inherit in the code you've pasted that requires stripslashes. – MatsLindh Dec 06 '12 at 17:47
  • just to say to @fiskfisk that he was right about this, and to excuse me for the wrong question. The problem was that i was checking same software (i was thinking...) on same type of machine, same lamp version, and only magic_quotes_gpc as difference between the 2 servers. Just to discover that one machine was doing the call to a geolocator server address while the other one was calling another geolocator. So i was receiving those nodes completely EMPTY on one of them. Again, thanks to fiskfisk and i am sorry for wrong question. – andymnc Dec 07 '12 at 11:39