Bug: Set BaseConnection instance as a property of it's property 'lastQuery' cause to 'circular reference'
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);
CI4 wasn't designed to support long-living PHP - it's quite a different architecture. You can check this project: https://ciburner.com
@michalsn Out of context, i'm trying FrankenPHP in my project. But Boot in CI4 need rework to support worker like https://github.com/php-runtime/frankenphp-symfony
But it's indeed a bug, good programs should not rely on bugs, right?
But it's indeed a bug, good programs should not rely on bugs, right?
I really don't see a bug here. PHP automatically closes database connections at the end of script execution, which is part of its garbage collection process.
But it's indeed a bug, good programs should not rely on bugs, right?
I really don't see a bug here. PHP automatically closes database connections at the end of script execution, which is part of its garbage collection process.
Sorry! It's my mistake, I misunderstanded about that.