Re: [PHP-DEV] Manual unset and GC

2025-03-11 Thread Edmond Dantes
Hello! In modern PHP, the garbage collector (GC) is not a mandatory component, provided that the code is written without circular dependencies. As soon as an object loses its last reference (i.e., its reference count reaches zero), PHP immediately frees the resources. In this sense, you can think

[PHP-DEV] Manual unset and GC

2025-03-10 Thread Vinicius Dias
Hello, folks. If this is not the correct place to ask, I apologize. > TL;DR: Does setting a variable to `null` (or even `unset`ing it) have **any** > effect if that's the last instruction of a function? The full version of the question with context: I have a question about the inner workings of

Re: [PHP-DEV] Manual unset and GC

2025-03-10 Thread Kamil Tekiela
Assuming that the variable gets created in the scope of the function and that it never leaks outside of the scope (e.g. by reference), then you can consider these things: PHP will destroy the object when there are no more references to it in the running script[1]. So, if the PDO object is limited

Re: [PHP-DEV] Manual unset and GC

2025-03-10 Thread Derick Rethans
On 10 March 2025 16:15:16 GMT, Vinicius Dias wrote: >Hello, folks. If this is not the correct place to ask, I apologize. > >> TL;DR: Does setting a variable to `null` (or even `unset`ing it) have >> **any** effect if that's the last instruction of a function? > >The full version of the question w

Re: [PHP-DEV] Manual unset and GC

2025-03-10 Thread Ilija Tovilo
Hi Vinicius On Mon, Mar 10, 2025 at 5:15 PM Vinicius Dias wrote: > > > TL;DR: Does setting a variable to `null` (or even `unset`ing it) have > > **any** effect if that's the last instruction of a function? As others have pointed out, it is _almost_ completely unobservable. There are two small d