f3-factory / fatfree-core

Fat-Free Framework core library
GNU General Public License v3.0
206 stars 89 forks source link

php8.1: Error - Array to string conversion #342

Closed pixeline closed 2 years ago

pixeline commented 2 years ago

When updating to php 8.1, (using F3 version 3.8) I get this error: "Array to string conversion" pointing at the copyfrom line here below.


$quote = new DB\SQL\Mapper($db, 'quotes');

if (!empty($_POST)) {

    $f3->set('POST.slug', create_slug($f3->get('POST.quote')));
    $quote->copyfrom('POST',function($val) {
        return array_intersect_key($val, array_flip(array('tags_id','author_id', 'source', 'status', 'quote')));
    });
  ...
}

Sample data sent via the form:

Array
(
    [tags_id] => Array
        (
            [0] => 13
        )

    [author_id] => 152
    [source] => https://love.com
    [quote] => test test  test
    [slug] => test-test-test
)

I do not understand what is wrong, can you help me ? Full trace:

[/var/www/html/app/vendor/bcosca/fatfree-core/base.php:2375] Base->error()
[/var/www/html/app/vendor/sentry/sentry/src/ErrorHandler.php:305] Base->{closure}()
[/var/www/html/app/vendor/bcosca/fatfree-core/db/sql.php:137] Sentry\ErrorHandler->handleError()
[/var/www/html/app/vendor/bcosca/fatfree-core/db/sql/mapper.php:101] DB\SQL->value()
[/var/www/html/app/vendor/bcosca/fatfree-core/db/sql/mapper.php:686] DB\SQL\Mapper->set()
[/var/www/html/app/controllers/quote-add.get.post.php:26] DB\SQL\Mapper->copyfrom()
[index.php:182] include('/var/www/html/app/controllers/quote-add.get.post.php')
pixeline commented 2 years ago

found it: the tags_id is stored in the db as a VARCHAR, so the mapper was (rightly) complaining about me trying to stuff it with an array.

Adding this line before the copyfrom operation solved it:

    $f3->set('POST.tags_id', implode(',', $f3->get('POST.tags_id')));