Skip to content

PHP warning array_flip() #391

@eric-hoppenworth

Description

@eric-hoppenworth

PHP Warning: array_flip(): Can only flip STRING and INTEGER values! in /var/www/html/site/vendor/klein/klein/src/Klein/DataCollection/DataCollection.php on line 135

I am running PHP version 7.2.5 And I get the warning consistently when hitting routes where I use GET parameters.

So I went into DataCollection.php and found the all() function that seemed to be causing the problem.
I var_dump($mask) just before it is passed into array_flip(). To my surprise, I see that one of the values passed in is actually a BOOLEAN (false).

array(2) { [0]=> string(3) "new" [1]=> bool(false) } 

I did not use that as part of my mask, but I notice that the mask is modified within the function, the rest of the function arguments are added in.

So I went over to Request.php, lines 282 thru 285 (the params() function)

return array_merge(
            $attributes,
            $this->params_get->all($mask, false),
            $this->params_post->all($mask, false),
            $this->cookies->all($mask, false),
            $this->params_named->all($mask, false) // Add our named params last
        );

There it is! A boolean is being passed in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions