|

PHP Java Properties

Java typically stores its configuration in files that end with a .properties extension. These files are essentially key-value pairs of data. Java SE has a built-in class, java.util.Properties, for reading and writing these files.

Sometimes, though, you may want to read these files from other languages. For example, database information is often stored in a .properties file. If another application wishes to connect to the same database, it is better to read that file rather than create a copy. That way, if the password changes (for example), you only have one place to update.

The basic syntax of the file is easy to understand. It is line-based. Each line is either a blank line, a comment line, or a key-value pair. Keys are separated from values by an =, :, or space. Easy, right?

Well, there are a few complications. You can read the full spec here, but this is a brief summary of some of the issues with creating a fully-compliant reader/writer:

So here is a working PHP port of the java.util.Properties class. Most of the common methods are implemented with the same name as their Java counterpart.  The header documentation of the class goes into more details on what is and is not implemented, and where to find the corresponding functionality.

Download here

matt( at )innerweaver.com