Forum Moderators: coopster

Message Too Old, No Replies

PHP Reserved word

php, reserved word

         

belfasttim

7:40 pm on Oct 6, 2009 (gmt 0)

10+ Year Member



Hi all--

I'm generating an INI file from a database, and one of the fields is Office, and the system code for this resource is OFF. The problem is that "OFF" is used as a key in other tables, so I can't really change it.

It appears that OFF is a php reserved word, because when I try to parse the INI file to get the values I need to look up in the other tables, I get Error parsing resource_types.ini and the hwole thing fails.

Any ideas on this? or how to workaround?

jatar_k

2:14 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't see it in the list of reserved words here
[php.net...]

are you sure that's the problem?

belfasttim

7:41 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



Hi Jatar--

Yeah, I didn't see it on the list of words either, but if I comment out the line writing "OFF" to the ini, it works fine, and if I use backticks around the word OFF it also works.

Note that the error isn't in the ini file-- it's from parse_ini_file(). Here's a sample ini file that will show you what I mean:

; test ini file

[Offices]
TEST = new value
OFF = my value

then:

<?php

$test = parse_ini_file("test.ini");

var_dump($test);

?>

At this point I think I'm just going to write the backticks around the key part of the ini file, then strip those backticks after I parse the ini. But it just seems like a hack and I'd rather have it working properly!

Thanks

sned

10:13 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



Looks like it is a sort of reserved word:

From [us2.php.net...]

" Note: There are reserved words which must not be used as keys for ini files. These include: null, yes, no, true, false, on, off, none. Values null, no and false results in "", yes and true results in "1". Characters {}¦&~![()^" must not be used anywhere in the key and have a special meaning in the value. "

belfasttim

10:51 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



Thanks Sned-- any thought on how to work around this (short of using the backticks and then stripping them out)?

As I said, I cna't change the OFF code in the database, since it's na external resource.

Thanks

sned

11:08 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



Hmm, you might be out of luck since you can't change it. Would there be any way to use a define statement somewhere? It may be easiest and quickest overall to just work around it as you mentioned above.

belfasttim

11:57 pm on Oct 7, 2009 (gmt 0)

10+ Year Member



Not really, since depending on the data source (there could be many!) this might be far from the only reserved word they use. So I guess I'll go with the hack.

Thanks for the help!