Page 1 of 1

what I want to do is impossible

Posted: Sat Dec 08, 2007 1:59 am
by s.dot
Or at least, extremely complex.

Basically I wanted to build a library that determines the minimum php version required to run an application. The logic is as follows:

1. Parse all files for the application with the php tokenizer. From this, you can determine if there are php 4.3, 5.0, 5.1 and 5.3 tokens. If there are, then your minimum version required is at least the highest version for the token encountered. If none of these version-specific tokens are encounters, then assume that the minimum version required is 0.0.

2. While tokenizing, store all of the functions (with parameters) encountered, and compare them to a (yet-to-be-made) dictionary of functions => version required. Of course, taking into account parameters added in later versions than when the function was introduced, and making special notes (e.g. version 5.1.0 now accepts parameter 2 of type array).

3. Determine the minimum php version required for the functions (which would be the highest funtion php required value)

4. Determine which is higher, the highest token version encountered, or the hights function version encountered.

Sounds simple, I thought.

But the problem comes with PHP objects such as RecursiveDirectoryIterator->next(). next() by itself is a function, but when used by RecursiveDirectoryIterator, it becomes a php5+ function.

I think a really complex regex would be needed to capture object->method (and ones specified by php, not user defined) strings based on tokens.

I've taken the liberty of writing the library all the way up to the point of comparing function versions, but now I am stuck on that. I'm really only doing it to enhance my OOP skills. I'm thinking I should scratch the library.

Unless I'm overcomplicating things and there's a much easier way?

Posted: Sat Dec 08, 2007 3:12 am
by Maugrim_The_Reaper
http://pear.php.net/package/PHP_CompatInfo

Sometimes the wheel is already invented :). Unlike the PEAR convention, this one is regularly maintained and released often. I've used it previously to figure out the minimum requirements of my projects, including PHP version, extensions needed, etc.

Posted: Sat Dec 08, 2007 8:13 am
by s.dot
Very nice.