ramblings on PHP, SQL, the web, politics, ultimate frisbee and what else is on in my life
back

YAML and PHP

If you use YAML in PHP, then you had until recently the choice between the C based PECL extension syck or the horrible spyc PHP based implementation. With syck it has the issue that it only supports the core standard and not stuff like merge-key, which is a very very useful extension to the core YAML standard.

Also you of course had to have the extension available, which can be painful if you have shared host using clients or worse yet those that use RHEL (side rant: Why the hell is DOM disabled in RHEL? Why do they keep their customers stuck on 5.1.6 for years? What is the deal with providing more than one stable PHP version in a 5 year release cycle of RHEL?).

So there you go, stuck with spyc, which is non standards compliant, gives no useful error messages and is slow. Well slow can be forgiven since its written in PHP (PHP6's goto might make writing parsers in PHP more fun and fast). As a result the Symfony project decided to write their own regexp based YAML parser. I hope the choice of using regexp will not come to hurt too much down the road, but in the current state it works much better than spyc and with a set of patches that are to be accepted into Symfony after the release of 1.1, there will be full merge-key support.

We are already using sfYaml in our framework here at Liip called Okapi. If others begin to use this parser, then we can pool ressources in maintenance and rid the world of the pain that is spyc.

Comments



Re: YAML and PHP

Great job! I kept hoping to interest the ZF in a very similar component but the Gods willed it be struck down by the conflicting messages from their proposal system at the time.

Re: YAML and PHP

I gave this parser some testing — it chokes on some basic yaml-documents

for example:

[{a: test}]

Timestamp-treating also could be better (syck uses php's DateTime class)

anyway, it is a good starting-point
am I correct, that this is supposed to be YAML-1.1 implementation? adding version-header to output would be nice

Re: YAML and PHP

@Alexey: Could you file bug reports over on http://trac.symfony-project.com/?

Re: YAML and PHP

There's also Horde_Yaml, that improves on spyc with a ton of tests and new features/fixes (including ArrayObject and Serializable support):

http://cvs.horde.org/framework/Yaml
http://pear.horde.org/index.php?package=Yaml

Re: YAML and PHP

yes, RHEL and CentOs has this isue wiyh stable PHP package, and I don't know why too, and I'm interested why too. But it's easy to compile last version of PHP on this platforms by yourself

Before you can post a comment please solve the following captcha.
your name