sofadesign/limonade

What version of PHP?

Closed this issue · 13 comments

I'm wondering what is the minimum supported version of PHP supported by Limonade? It certainly works on 5.2.17, but I was interested in getting it working in a positively ancient 5.1. Is it likely to work or are major incompatibilities likely?

At any rate, it is probably worth putting the requirements in the readme.

Thanks again for making such an awesome framework.

I recently used it on 5.1.6. We've made some little fixes to make it work but it was trivial.

I think it should be ok with older version too. Which version will you use exactly ?

Hmm... strange.

I just tried Limonade on PHP 5.1.6 and I can't get it working at all. I downloaded an old version of MAMP 1.4.1, that comes with 5.1.6 and everything explodes. I cloned the limonade repo and pointed a vhost directly at the root of the repo. I created a config file with:

    $config['limonade_base_url'] = 'http://localhost:8903/';

Then opened /tests/all.php.

Out of the gate, there is a minor issue with one of the defines.

   PHP Fatal error:  Call to undefined function memory_get_usage() in /Users/philoye/code/php/vendor/limonade/lib/limonade.php on line 63

memory_get_usage() doesn't exist unless PHP was specifically compiled with --enable-memory-limit. I have no idea how common it is in the wild, but at least MAMP apparently didn't include it.

Then I get:

   PHP Warning:  call_user_func_array() [<a href='function.call-user-func-array'>function.call-user-func-array</a>]: Unable to call TestCallIfExists::testStatic() in /Users/philoye/code/php/vendor/limonade/lib/limonade.php on line 1842

Also get:

    PHP Parse error:  syntax error, unexpected T_FUNCTION in /Users/philoye/code/php/vendor/limonade/tests/apps/03-routing.php on line 49`

(repeated ~20 times)

This is the test for the 5.3 lamda routing, which shouldn't occur in 5.1.6 but nevertheless it is failing here.

Also get:
PHP Notice: Undefined offset: 1 in /Users/philoye/code/php/vendor/limonade/tests/apps/09-redirect.php on line 12`

(repeated 3 times)

So I'm not sure whether there is something messed up in MAMP or I'm missing something. Any help would be appreciated.

Also just noticed that at least one function that you are relying on isn't supported in 5.1: json_encode, on line 1548:

   function json($data, $json_option = 0)
   {
     if(!headers_sent()) header('Content-Type: application/json; charset='.strtolower(option('encoding')));
      return version_compare(PHP_VERSION, '5.3.0', '>=') ? json_encode($data, $json_option) : json_encode($data);
    }

the json_encode() function doesn't make an appearance in PHP until 5.2, though there are several implementations to backport it.

Ok, last comment for the night. All of the examples under 5.1.6 seemingly work except for example02, which has an issue with the aforementioned json_encode():

    Notice: Undefined index: function in /Users/philoye/code/php/vendor/limonade/examples/example02/index.php on line 15

    Fatal error: Call to undefined function json_encode() in /Users/philoye/code/php/vendor/limonade/examples/example02/index.php on line 16

Ok, this only requires small patches. I've created a working branch: https://github.com/sofadesign/limonade/tree/for-php5.1.x

I'll try to make fixes this week.

You're a star! Thank you!

I've pushed fixes on the for-php5.1.x branch. Can you tell me if everything's ok before I merged it in master branch ? About the json_encode() function, I prefer to let the user choose its implementation, so I've only added a warning that will be raised when you call json_encode() if it's not available.

Wow, that was fast. I just did a test and all my stuff works. Thank you!

The only issue I ran into is that I had to provide my own implementation of json_encode before requiring Limonade. I originally had it after Limonade but before I called json_encode causing it to complain that json_encode was already defined. Turns out Limonade was defining it to provide the warning. Easy fix, though perhaps the warning message could be more clear?

Again, thanks for this. I'd recommend placing some wording about PHP requirements in the README.

I ran /tests/all.php in the browser, under 5.1.6 and got a single failure:

## MAIN
Testing limonade main functions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
�[01;33 mAssertion failed�[00m in script     */Users/philoye/code/php/vendor/limonade/tests/main.php* (line 86):
   * assertion: assert_equal($app_file, strtolower($env['SERVER']['PWD'].'/'.$env['SERVER']['PHP_SELF']));
   * message:   <1> should be equal to <2>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
�[01;31 m|FAILED!|�[00m Test case 'main' finished: 11 tests,  1 failures for 110 assertions.
-----------------------------------------------------------

Well, I probably should've run the tests in a new version to see if it is a 5.1.6 issue, it isn't. I get the above error in 5.3.3. as well.

I also get a few more errors/warnings. Again, I haven't run into them for my code, but I thought I'd provide them in case they help you.

## FILE
Testing limonade file functions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Warning: finfo_file(): Empty filename or path in /Users/philoye/code/php/vendor/limonade/lib/limonade.php on line 2404
Warning: finfo_file(): File or path not found 'my_file' in /Users/philoye/code/php/vendor/limonade/lib/limonade.php on line 2404
Warning: finfo_file(): File or path not found 'my_file' in /Users/philoye/code/php/vendor/limonade/lib/limonade.php on line 2404
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
�[01;32 m|PASSED|�[00m Test case 'file' finished: 6 tests,  0 failures for 35 assertions.
-----------------------------------------------------------

## FUNCTIONAL
Functional tests
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
�[01;33 mAssertion failed�[00m in script */Users/philoye/code/php/vendor/limonade/tests/functional.php* (line 185):
   * assertion: assert_match("/ON DISPLAY 2/", $response);
   * message:   <2> expected to match regular expression <1>
�[01;33 mAssertion failed�[00m in script     */Users/philoye/code/php/vendor/limonade/tests/functional.php* (line 189):
   * assertion: assert_match("/ON DISPLAY 3/", $response);
   * message:   <2> expected to match regular expression <1>
�[01;33 mAssertion failed�[00m in script */Users/philoye/code/php/vendor/limonade/tests/functional.php* (line 193):
   * assertion: assert_match("/ON DISPLAY 4/", $response);
   * message:   <2> expected to match regular expression <1>
�[01;33 mAssertion failed�[00m in script     */Users/philoye/code/php/vendor/limonade/tests/functional.php* (line 194):
   * assertion: assert_match("/NO FLASH MESSAGE ON NEXT PAGE/", $response);
   * message:   <2> expected to match regular expression <1>
�[01;33 mAssertion failed�[00m in script */Users/philoye/code/php/vendor/limonade/tests/functional.php* (line 198):
   * assertion: assert_match("/REDIRECTED FROM INDEX FIVE/", $response);
   * message:   <2> expected to match regular expression <1>
�[01;33 mAssertion failed�[00m in script */Users/philoye/code/php/vendor/limonade/tests/functional.php* (line 199):
   * assertion: assert_match("/ON DISPLAY 6/", $response);
   * message:   <2> expected to match regular expression <1>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
�[01;31 m|FAILED!|�[00m Test case 'functional' finished: 6 tests,  6 failures for 55 assertions.
-----------------------------------------------------------

## OUTPUT
Testing limonade output functions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
�[01;33 mAssertion failed�[00m in script */Users/philoye/code/php/vendor/limonade/tests/output.php* (line 26):
   * assertion: assert_equal($response, $lorem);
   * message:   <1> should be equal to <2>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
�[01;31 m|FAILED!|�[00m Test case 'output' finished: 8 tests,  1 failures for 35 assertions.
-----------------------------------------------------------

Hopefully it helps. Thanks again for making this awesome library...

Cheers,
p.

Thx for your feedback.

Some warnings are normal and others are because tests are running in the browser, as their made for shell only.

About when calling the load of your json_encode implementation, I think it would be better if we can just do that the normal way we load libraries. I'll make some changes to allow that behaviour.

About the json_encode warning message, have you got a sentence to suggest me ?

In terms of a sentence, how about:

__FUNCTION__ . '(): no JSON functions available. Please provide your own implementation of ' . __FUNCTION__ . '() before requiring Limonade.', E_USER_WARNING

I've merge the for-php5.1.x branch with master. I've also added a little fix: it's no longer required to load your own json_encode implementation before Limonade. It can be loaded the normal way like any other lib.