Skip to content

Bug: when() & whenNot() evaluate empty array to true #9575

@ECode16

Description

@ECode16

PHP Version

8.3

CodeIgniter4 Version

4.6.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

No response

What happened?

If condition for function when() or whenNot() in ConditionalTrait is empty array the function evaluate it to true (as opposed to PHP which evaluates it to false).

Steps to Reproduce

when([], $callback)

Expected Output

Callback not called.

Anything else?

Same thing is happening with "0", 0 and 0.0, if this behaviour is intentional I believe it should be mentioned in description and user guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions