WordPress / playground-tools

GNU General Public License v2.0
127 stars 38 forks source link

VS Code Extension: Windows 10 and PHP versions lower than 8.0 #13

Open jonathanbossenger opened 1 year ago

jonathanbossenger commented 1 year ago

On Windows 10, if you try and launch the playground on anything lower than PHP 8.0 (so 7.4 and older) the following PHP error is reported:

Fatal error: Uncaught Error: Call to undefined function str_ends_with() in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-lexer.php:2291 Stack trace: #0 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-lexer.php(1490): WP_SQLite_Lexer->parse_unknown() WordPress/wordpress-playground#1 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-lexer.php(1442): WP_SQLite_Lexer->lex() WordPress/wordpress-playground#2 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php(722): WP_SQLite_Lexer->__construct('SELECT option_n...') WordPress/wordpress-playground#3 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-translator.php(594): WP_SQLite_Translator->execute_mysql_query('SELECT option_n...') WordPress/wordpress-playground#4 /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php(282): WP_SQLite_Translator->query('SELECT option_n...') WordPress/wordpress-playground#5 /var/www/html/wp-includes/wp-d in /var/www/html/wp-content/plugins/sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-lexer.php on line 2291

Versions of PHP 8.0 and above, however, seem to work fine.

adamziel commented 1 year ago

Thank you for reporting!

That's interesting – str_ends_with was added in PHP 8.0 and WordPress provides polyfills, but it looks like they're not loaded for some reason. Definitely a bug. Most likely wp-now is affected, too.

dmsnell commented 1 year ago

it looks like they're not loaded for some reason.

my initial guess was that we were running an older version of WordPress as well, which didn't have it. or could this code be loading before that polyfill is created?

jonathanbossenger commented 1 year ago

it looks like they're not loaded for some reason.

my initial guess was that we were running an older version of WordPress as well, which didn't have it. or could this code be loading before that polyfill is created?

Ah, this is possible, I just loaded the playground on a version of WordPress I had installed on my Windows boot, it may need an upgrade. I will check and report back.

dmsnell commented 1 year ago

either way @jonathanbossenger the extension shouldn't crash. this is a case of forgetting that older versions of WordPress exist.

jonathanbossenger commented 1 year ago

Gotcha, but it will be good to confirm if the bug is in the actual extension (which might not be the case here) or the SQLite plugin, in cases where the polyfills might not be in place, ie user launching the extension but on a WordPress install that's older than x.

jonathanbossenger commented 1 year ago

Confirming that the error happens when running the VS Code extension on a folder with an old version of WordPress. Running it on WordPress 6.2.1 works perfectly.

adamziel commented 1 year ago

Good to know! Well, it should still work on those previous versions, thank you for reporting @jonathanbossenger !

danielbachhuber commented 1 year ago

@adamziel It looks like the polyfill was added in WordPress 5.9:

https://github.com/WordPress/wordpress-develop/blob/a10e2bcf05309b814d7aba32281d24fe30eaf65b/src/wp-includes/compat.php#L471-L493

And the SQLite extension requires 6.0:

https://github.com/WordPress/sqlite-database-integration/blob/738e3bc64be359504197371d6a2436d04e3848dd/readme.txt#L4

I guess we can only support WordPress 6.0 and higher?

jonathanbossenger commented 1 year ago

FWIW I think that's perfectly fine, and all we'd need to do is add this to the usage instructions somewhere.

I plan to create a PR to add some usage instructions soon, that link from the Extension sidebar, so that should cover this issue.

adamziel commented 1 year ago

And the SQLite extension requires 6.0:

I don't think it does, though. It works fine with 5.9 and older releases. @aristath – what do you think about updating that number?