Skip to content

Bug: Set BaseConnection instance as a property of it's property 'lastQuery' cause to 'circular reference' #9386

Open
@warmbook

Description

@warmbook

PHP Version

8.1

CodeIgniter4 Version

4.5.4

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

cli

Database

No response

What happened?

Run in a 'Resident Process Mode' such as swoole, a BaseConnection instance would never destruct after query database because of 'circular reference', which means memory leak.

Steps to Reproduce

Query database in a 'Resident Process Mode' such as swoole, echo something in it's __destruct method, nothing will output because the instance won't destruct at all.

Expected Output

The instance should be able to destruct.

Anything else?

Only two methods are used in Query instance: 'isWriteType' and 'escape', which seems could work as static methods. Why not set them as static methods and pass the full class name of BaseConnection instance to Query instance just like $query = new $queryClass(static::class);, then we can call those two methods like $this->dbClass::isWriteType($this->originalQueryString).
Another simpler suggestion is to clone the BaseConnection instance like $query = new $queryClass(clone $this);

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