Zum Inhalt der Seite gehen


You want a crazy idea? Add an "__outScope" built-in method for classes.

It will run when the scope of the variable that holds the class instance ends.

Imagine the possibilities.

#PHP #Programming #Software #SoftwareDevelopment #WebDevelopment #WebDev #ApplicationDevelopment #AppDevelopment #Coding #Code

Als Antwort auf Larry Garfield

@Crell I believe it's not the case, because the descrutor is called when garbage collecting the class, and never called if it goes out of scope but the instance lives somewhere else.
Als Antwort auf .:\dGh/:.

You want a variable destructor separate from the object destructor? Dear God why?
Als Antwort auf .:\dGh/:.

In PHP, there's scarce few use cases for it. Object destructor or a closure handle most of them. There is discussion of defer in the case of async happening right now on the Internals list, though.
Als Antwort auf Larry Garfield

@Crell Hopefully it goes well, that `defer` thing is one of my wishlist for PHP.

medium.com/@darkghosthunter/ph…

Als Antwort auf .:\dGh/:.

No one is proposing what you are talking about there. I don't think it would make any sense in PHP.
Als Antwort auf Larry Garfield

@Crell I'm pretty sure defer in Golang is used to run code when a function exists, not when a variable goes out of scope. It's used to clean up connections or close file descriptors in long running code. Possibly not go hard to add to PHP, but I'm curious what an actual (non contrived) use case is.

Diese Webseite verwendet Cookies. Durch die weitere Benutzung der Webseite stimmst du dieser Verwendung zu. https://inne.city/tos